You are viewing the Understanding Syntax tutorial
Tutorial Selection
Tutorial Contents
What are variables?
A variable is a method of storing data. Variables, in programming, are often given names which can be referred to later when coding. While Minecraft hardly touches on variables, the basics are explained here anyway. For more detail about command-specific syntax, you'll want to see tutorial 4. Variables can store all kinds of data which can then easily be referenced in code using just the name. Variables can store text, whole numbers, decimals, boolean values and even lists of data. Though lists are technically referred to as "lists", rather than variables themselves. This tutorial will just explain the basics, that you may come across throughout the world of Minecraft Bedrock commands.
String
A string variable is used to store text. String variables can hold a sequence of letters, numbers and symbols. It should be noted that a computer will see numbers stored in a string variable as text and not numbers. You would use numbers in a string when you want to preserve the leading zeros, format the number or simply just don't want to perform mathematical equations on them. A good example use of strings being used in Minecraft is the new block states, they use strings to refer to different data. For example, in the old syntax (which used data values), you would write hardened_stained_clay 14 for red-stained terracotta. Now in the new syntax, you use two string values to tell the game you want it as red, this is written as hardened_stained_clay ["color": "red"]. The string values are "color" and "red".
Integer
An integer variable is used to store whole numbers. Integer variables can only hold whole numbers, they shouldn't be used for decimal/fractional numbers. Integers, more commonly referred to as "int", can be used in mathematical equations and to save memory because it is a smaller data type than a decimal. A good example use of integers being used in Minecraft is in the /setmaxplayers command. The command syntax asks for <maxPlayers: int>, meaning it wants a whole number.
A 32-bit signed (positive/negative) integer is a whole number with a minimum value of -2,147,483,648 and a maximum value of 2,147,483,647 (inclusive). A 32-bit unsigned (positive) integer has a minimum value of 0 and a maximum value of 4,294,967,295 (inclusive). Though in Minecraft Bedrock, only 32-bit signed integers are used, at least to my knowledge.
Decimal
A decimal variable is used to store decimal numbers. Decimal variables can be used to store whole numbers, but more specifically, they should be used for decimal or fractional numbers. A decimal variable is often confused for a "double" variable, but they are not the same. A double variable is a type of floating-point variable that can hold a wider range of values than a decimal variable but with less precision. A decimal variable is used for more precise calculations. A good example use of decimal variables in Minecraft is in the /fill or /clone command. While the coordinates are labelled with syntax such as <from: x y z> and <to: x y z>, the coordinates entered don't have to be whole numbers. In fact, entering a whole number as a coordinate in Bedrock Edition of Minecraft will automatically correct it to the centre of the block, 0 becomes 0.5.
Boolean
A boolean variable is used to store logical values, being true or false. Booleans are often referred to as "bools". A boolean can only hold one of two types of logical data, true or false. You can also consider it as 0 or 1, off or on, etc. Two values with opposite states essentially. However, saying that it should always be written as true or false. A good example use of boolean variables in Minecraft is again in the new block states. As an example, in the old syntax, you would place a pressed-down oak button using wooden_button 8, now you would write wooden_button ["button_pressed_bit": true].
Â