Variables
Introduction#
Sometimes, you want a single numerical variable that is not tied to a specific objective. For example:
- A
countervariable, that just counts from a number to another one. - A
numberOfEntitiesvariable, that counts the number of entities in the game. - Any variable that does not require a whole objective.
Sandstone allows you to directly write those variables, without creating the objective yourself, nor writing any command.
Syntax#
To create a variable, the following syntax can be used:
Variables are just an instance of a score holder's score. You can use all the methods they have, including all operations and comparisons: add, remove, divide, multiply, equals, greaterThan...
There are two kind of variables: global variables, and scoped variables.
Global variables#
Global variables are not declared inside any MCFunction. They will be initialized during the datapack loading. If an initial value has been given, each time the datapack is loaded, the variable will be set to this initial value.
Scoped variables#
Scoped variables are declared inside a given MCFunction. Each time the function is called, the variable will be initialized and set to its initial value (if any).