Variables
Variables are used to store data to be used later. There are different types of variables for numbers and booleans.
In Minecraft, these variables are stored in scoreboards, tags, and NBT storages, depending on the type of data. Shulkerscript provides a way to work with these variables in a more abstract way.
Integer Variables
Section titled “Integer Variables”Integer variables are used to store whole numbers. They can be created using the int keyword.
// Create an integer variable called myIntint myInt = 42;
// Create an array of integersint manyInts[5] = [1, 2, 3, 4, 5];// Access the third element of the array (indexing starts at 0)manyInts[2] = 42;
// Create an entity-integer map/scoreboardint myScore[];// Set the score of the nearest player to 42myScore["@p"] = 42;The scoreboard objective can be accessed with myInt.objective and the target/targets with myInt.target/myInts.targets.
Operations
Section titled “Operations”You can perform operations on integer variables, such as addition, subtraction, multiplication, and division.
int a = 5;int b = 3;int c = a + b; // c is now 8int d = a - b; // d is now 2int e = a * b; // e is now 15int f = a / b; // f is now 1, integer divisionint g = a % b; // g is now 2, remainder of the divisionBoolean Variables
Section titled “Boolean Variables”Boolean variables are used to store true or false values. They can be created using the bool keyword.
// Create a boolean variable called myBoolbool myBool = true;
// Create an array of booleansbool manyBools[5] = [true, false, true, false, true];
// Create an entity-boolean map/tag and set the value of the nearest player to true at the same timebool myScore["@p"] = true;The tag or storage name can be accessed with myBool.name and the storage path with myBools.path.