|   |   | 
| (5 intermediate revisions by 2 users not shown) | 
| Line 1: | Line 1: | 
|  | {{Block |  | {{Block | 
|  | |image=Set_Variable.png |  | |image=Set_Variable_number.png | 
|  | |type=s |  | |type=s | 
|  | |folder=Variables |  | |folder=Variables | 
| Line 9: | Line 9: | 
|  | 
 |  | 
 | 
|  | Stores the input value into a variable. |  | Stores the input value into a variable. | 
|  | Think of a variable as a container with a nametag that can only store one value at a time.
 |  | 
|  | If you were to set another value to a variable, it will overwrite the previous value of that variable.
 |  | 
|  | 
 |  | 
 | 
|  | You can get/output the value from a variable with the same name and type using the [[Get Variable]]block.
 |  | See [[Variables]] for more information. | 
|  | 
 |  | 
 | 
|  | [[File:Set_Variable_inspect_value.png]]
 |  | == Notes == | 
|  | 
 |  | 
 | 
|  | == Global variables ==
 |  | If {{Port|?|Value}} remains not wired, the variable will not be overwritten. | 
|  |  | This could be used to provide default values for a custom script block: | 
|  | 
 |  | 
 | 
|  | Let's say you have a script inside a block that sets avariable to 1,and you have a script outside of the block to inspect that variable.
 |  | [[File:Set_Variable_default_value.png|thumb|none|Demonstration applying a default value, 2. The variable is global for inspection.]] | 
|  | 
 |  | 
 | 
|  | [[File:Set_Variable_global_example.png]]
 |  | == Related == | 
|  | 
 |  | 
 | 
|  | As you can see, we've set the variable to 1, but the Get Variable block outputs 0 as if we never set the variable in the first place.
 |  | * [[Variables]] | 
|  |   |  | * [[Get Variable]] | 
|  | This is because those two variables are local, meaning they can't transfer variable information from one place to another (inside a block to outside the block, or into another block and vice versa).
 |  | * [[List Element]] | 
|  |   |  | * [[Set Reference]] | 
|  | If we want a variable to share information to another variable in different places, then we would have to globalize them.
 |  | 
|  | You can simply press the Global button on the keyboard where you type the variable's name. Global variables gain a `$` at the start of their name.
 |  | 
|  |   |  | 
|  | Note that two variables with the same name with one being a global will not count as the same variables (e.g `Number` and `$Number` are not the same).
 |  | 
|  |   |  | 
|  | [[File:Set_Variable_button_global.png]] |  | 
|  |   |  | 
|  | == Saved variables ==
 |  | 
|  |   |  | 
|  | Saved variables were added in Fancade 1.6. Like global variables, you can make a saved variable by pressing the Local/Global/Saved button on the keyboard where you type the variable's name.
 |  | 
|  | Saved variables gain a `!` at the start of their name.
 |  | 
|  |   |  | 
|  | [[File:Set_Variable_button_saved.png]] |  | 
|  |   |  | 
|  | As the name implies, saved variables persist their value from one game session to the next.
 |  | 
|  | This is true whether the user ends the game by winning, dying, or simply pausing and returning to the menu.
 |  | 
|  |   |  | 
|  | Additionally, saved variables are shared across all levels in the same game.
 |  | 
|  | This allows a player's actions in one level to affect their gameplay in other levels, and to keep track of purchases from the [[Menu Item]]block. 
 |  | 
|  |   |  | 
|  | Saved variables currently only have number type and there can be up to 64 saved variables per game.
 |  | 
|  | 
 |  | 
 | 
|  | [[Category:Blocks]] |  | [[Category:Blocks]] |