Set Reference: Difference between revisions
Rework on example, with meaningful image names, use existing templates
Nikitaivanov (talk | contribs) (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...") |
-u ndefined- (talk | contribs) (Rework on example, with meaningful image names, use existing templates) |
||
Line 1: | Line 1: | ||
{{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 | 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. | ||
In the early days of Fancade, this was the only way to set a variable's value. | |||
{{Image|Set_Reference_example1.png|Setting a variable value with Set Reference.}} | |||
== Example == | == Example == | ||
You can find an example of making lists in the [[List Element]] page. | You can find an example of making lists in the [[List Element]] page. This page will focus on another use. | ||
We will recreate the [[Increase Number]] block (by using a script block): | |||
{{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? | ||
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. | |||
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: | |||
{{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]] |