You are viewing the Understanding Syntax tutorial
Tutorial Selection
Tutorial Contents
A "variable", in programming terms, is a method of storing data. Think of them as named storage locations for storing different types of data. In Minecraft, you'll not be creating variables when using commands; however, commands are built to accept different types of data that you'll need to provide. Whilst doing commands in Minecraft, you will come across variable terminology as well. Data assigned to variables are split into what are called "data types", these are: "strings", "integers", "decimals", and "booleans". Additionally, you may also come across a special type of data, called a "list".
A "string variable", or "string data type", is a variable that stores text. This type of variable can store any sequence of letters, numbers, or symbols. Whilst a string variable can store numbers, computers still see this data as text. Numbers are often used in string variables when you're trying to preserve leading zeros, format the number, or avoid mathematical equations. In Minecraft, several commands are built to accept the string data type (e.g. /msg <target: target> <message: message>).
Note: "string" is often shortened to "str"
An "integer variable", or "integer data type", is a variable that stores whole numbers. This type of variable only stores numbers that are whole, this means text, symbols, and decimals are not accepted. An integer variable is often used in mathematical equations and to save memory (integers take up less space than decimals). In Minecraft, several commands are built to accept the integer data type (e.g. /setmaxplayers <maxPlayers: int>). An integer can hold larger or smaller numbers depending on the number of binary digits (bits) a computer uses to store that number. For example, a 16-bit integer can hold a larger number than an 8-bit integer, a 32-bit integer can hold a larger number than a 16-bit integer, and so on. The more bits, the larger the number the integer can store.
A "signed integer" is a whole number that can be positive, negative or equal to zero. The name stems from the bit of information included (the "sign bit") that indicates whether the number is positive or negative. Here are some examples of the minimum and maximum values a signed integer can store depending on the number of bits used to store it:
An 8-bit signed integer can hold any number within the range of -128 to 127
A 16-bit signed integer can hold any number within the range of -32,768 to 32,767
A 32-bit signed integer can hold any number within the range of -2,147,483,648 to 2,147,483,647
An "unsigned" integer" is a whole number that can only be positive or equal to zero. An unsigned integer doesn't have a "sign bit", this means it can store a larger positive number whilst taking up the same amount of memory as a signed integer. Here are some examples of the minimum and maximum values an unsigned integer can store depending on the number of bits used to store it:
An 8-bit usigned integer can hold any number within the range of 0 to 255
A 16-bit unsigned integer can hold any number within the range of 0 to 65,535
A 32-bit unsigned integer can hold any number within the range of 0 to 4,294,967,295
Note: "integer" is often shortened to "int"
A "double variable", or "double data type", is a variable that stores numbers with a decimal point. This type of variable is often used for things that require precision, such as: coordinates, distances, or speeds. Double variables can store a wide range of values, including positive and negative numbers. While this type of variable can accept whole numbers (e.g. 7 or -32), the game will still read and store them with a decimal point (e.g. 7.0 or -32.0). The double data type does not accept text or symbols. In Minecraft, several commands are built to accept the double data type (e.g. /tp <destination: target>). In the Bedrock Edition of Minecraft specifically, coordinates are always centre-corrected (e.g. 57.0 becomes 57.5), this is commonly seen when using the teleport command.
Note: In programming, a "double" is a specific type of floating-point number, which is a term for any number with a decimal point. It's often used because it's more accurate than a float (which, for simplicity, we won't go into).
A "boolean variable", or "boolean data type", is a variable that stores only one of two values, true or false (on or off, 0 or 1, yes or no, etc); two opposite values. In Minecraft, several commands are built to accept the boolean data type (e.g. /gamerule <rule: BoolGameRule> [value: Boolean]).
Note: "boolean" is often shortened to "bool"
Missing content; to be added.