Variables
#
IntroductionSometimes, you want a single numerical variable that is not tied to a specific objective. For example:
- A
counter
variable, that just counts from a number to another one. - A
numberOfEntities
variable, 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.
#
SyntaxTo 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 variablesGlobal 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 variablesScoped 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).