Set Reference: Difference between revisions

Rework on example, with meaningful image names, use existing templates
(Created page with "/uploads/Set Reference.png Like Set Variable, but with an additional input for the variable to store the value in. This enables you to store a variable in a List Element, or make custom script blocks that modify variables. Inputs: * Variable: the variable to be modified. This can be connected to the output of List Element to set the respective index of the variable. * Value: the new value given to the variable. == Example == You can find...")
 
(Rework on example, with meaningful image names, use existing templates)
Line 1: Line 1:
[[width=336px|/uploads/Set Reference.png]]
{{Block
|image=Set Reference number.png
|type=s
|input1={{Port|e|Before}}
|input2={{Port|?|Variable}}
|input3={{Port|?|Value}}
|output1={{Port|e|After}}
}}


Like [[Set Variable]], but with an additional input for the variable to store the value in. This enables you to store a variable in a [[List Element]], or make custom script blocks that modify variables.
Like [[Set Variable]], but with an additional input for the variable to store the value in. This enables you to store a variable in a [[List Element]] by connecting it to the Variable port, or make custom [[Script Block|script block]]s that modify variables.  


Inputs:
In the early days of Fancade, this was the only way to set a variable's value.


* Variable: the variable to be modified. This can be connected to the output of [[List Element]] to set the respective index of the variable.
{{Image|Set_Reference_example1.png|Setting a variable value with Set Reference.}}
* Value: the new value given to the variable.


== Example ==
== Example ==


You can find an example of making lists in the [[List Element]] page. So we'll focus on another use.
You can find an example of making lists in the [[List Element]] page. This page will focus on another use.


Let's say we want to recreate the [[Increase Number]] block.
We will recreate the [[Increase Number]] block (by using a script block):


[[File:Screenshot_20210110-134113_Fancade.jpg]]
{{Image|Set_Reference_example2_increment1.png|One input port, which is added by 1.}}


We have the increased number, now we have to set that value to the input variable, but how?
This script block takes a variable, either by [[Get Variable]] or List Element. We have the increased number, now we have to set that value to the input variable, but how?


The Set Reference block was the originally how we set variables, until the Set Variable with only a value input was added, which is limited but more convenient and optimal. But Set Reference can be used for custom script blocks that modify input variables.
Set Variable cannot work in this case as it can only modify the variable as deemed by the user for the entire duration. And worse, it is by default [[Set Variable#Global_variables | local]] and so the variable we would like to increment remains unchanged. Other variable modes are impractical as well.


[[File:Screenshot_20210110-135616_Fancade.jpg]]
Therefore, we will have to use a more versatile script block. Set Reference allows to modify the variable on the left-hand side as named by the user:


[[File:Screenshot_20210110-135813_Fancade.jpg]]
{{Image|Set_Reference_example2_increment2.png|The final script.}}


== Related ==
== Related ==
Line 28: Line 34:
* [[List Element]]
* [[List Element]]
* [[Set Variable]]
* [[Set Variable]]


[[Category:Blocks]]
[[Category:Blocks]]