Scene variables
Scene variables are variables which are:
- stored in memory for the duration of a scene,
- can only be accessed from within the current scene.
They're useful for storing data that doesn't need to be shared between different scenes, such as the number of targets remaining in the level. They're deleted from memory when the player changes scenes.
Creating scene variables
- Open the Scene editor.
- Right click on the scene.
- Select Scene properties.
- Select Edit scene variables.
In the editor, choose "Add a variable", then enter a name, choose a data type and, optionally, enter a default value for the variable (this will be the value used when the scene starts).
Tip
Variable names should not contain dots (periods), commas or spaces. Other characters are also reserved by GDevelop. If you use something forbidden, GDevelop will automatically correct the name you've entered.
Using scene variables in expressions
You can use scene variables in expressions. Just write the name of the variable to use it in a formula. Note that if an object is using the same name, it will take the priority over the scene variable.
Note
You can also access variable using the expressions Variable(<name of the variable>)
(for a variable containing a number) and VariableString(<name of the variable>)
(for a variable containing a text). For example: GlobalVariable(TotalScore)
.
These expressions are more verbose and not recommended to use anymore, but will still work and you can find them in some games.