Variables
Variables can be used to store state in the game. Variables are stored uniquely for the user and will persist when the user stops the game and come back later.
A variable value can either be a string, boolean, number or object.
Creating variables
The most basic way of creating a variable is to use the modify state-node. Set the name and value of the variable:
Other nodes that can be used to set variables:
- Roll Dice - roll dice and store value in variable
- Random Number - store random number
- Loop - stores the loop index in a variable
- Http Request - make a http request and save response in variable
- Script - use JavaScript to use and modify variables
Using variables
Variables can be used in many other nodes by enclosing the variable name in curly brackets like this: {my_variable}
.
Variables can be used in most of the text input fields including in Say-, Display- and Condition-nodes. During execution,
the curly bracket and the variable is simply replaced with the stored value.
Warning
If the variable does not exist at the time it is used the value false
will be used.
Example
Here the variable coinAmount
is used in a say-node: