Variables

From Fancade Wiki
Revision as of 05:20, 22 June 2024 by Osmo (talk | contribs) (Created the page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Think of a variables as a container with a name that can only store one value at a time. The value in a variable can be changed by using Set Variable, and the value stored in a variable can be read by using Get Variable.

Storing and retrieving a number.

If you were to set another value to a variable, it will overwrite the previous value of that variable.

Variables can have different modes: Normal, Global and Saved. Any variable can also be a List

The mode of the variable can be changed by pressing the button at the bottom left while editing it's name.

Keypad shown with mode being changed to Global.

Variables of different types (Number, Vector, Object, etc.) and different modes can have the same name and are considered different variables. For example, Number and $Number are different variables.

Global variables

Global variables refer to the same value anywhere in a level.

Let's say you have a script inside a block that sets a variable to 1, and you have a script outside of the block to inspect that variable.

Set Variable in a script block. On the ground, inspecting its value shows 0 due to locality.

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.

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).

If we want a variable to share information to another variable in different places, then we would have to make them global. Global variables gain a $ at the start of their name.

Saved variables

Saved variables are similar to global variables, but their value persists between levels and game sessions. They can be used to keep track of purchases from the Menu Item block.

Saved variables gain a ! at the start of their name.

Keypad shown with mode being changed to Saved.

Saved variables currently only have number type and there can only be up to 64 saved variables per game.