If / Else
You can easily check for in-game conditions using Sandstone's builtin if
statement.
Syntax#
To check a condition, the following syntax is used:
As you can see, this syntax mimicks the original if / else if / else construct
from classical programming languages. elseIf and else are entirely optional,
and you can chain as many elseIf as needed:
Conditions#
Conditions are created using Sandstone's built-in abstractions.
Score conditions#
To check if a score matches a given condition, you can use score comparison operators.
For example:
Try it out#
Data conditions#
To check if a block, an entity or a storage has some NBT
data, use the _.data condition together with the NBT path syntax.
In the following example, a command is run every tick for each player holding a stick in their hand:
The same can be done for blocks:
caution
Please note that no validation is performed on NBT paths. The following snippet produces an invalid command due to missing quotes:
This is the resulting command:
Try it out#
Block conditions#
Block conditions can test for a block at a specified location or compare blocks at one volume with another volume.
Single block#
To test for a single block, use _.block. It takes the block's location as the
first argument and the block to test for as the second.
In the following example a function tests for a specific block below each player:
Block volumes#
In order to compare two block volumes, the area must be specified first using two coordnates and then the coordinates of the corner with the lowest coordinates (lower northwest corner). Additionally, it must be specified whether air blocks should be ignored when comparing. For more information, take a look at the Minecraft Wiki.
The following example compares the 3x3 area of blocks below the player with the area above them:
Try it out#
Boolean logic in programming means comparing boolean values (true/false)
with a defined outcome. Each boolean operation has a "truth-table" showing which
inputs lead to what output.
Or#
The _.or operation succeeds if one or more of its conditions are true. It can
have more than just two conditions as inputs.
| A | B | result |
|---|---|---|
| โ | โ | โ |
| โ | โ | โ |
| โ | โ | โ |
| โ | โ | โ |
Example:
And#
The _.and operation succeeds if all its conditions are true. It can
have more than just two conditions as inputs.
| A | B | result |
|---|---|---|
| โ | โ | โ |
| โ | โ | โ |
| โ | โ | โ |
| โ | โ | โ |
Example:
Not#
The _.not operation succeeds if its condition is false. It can only have one
input.
| A | result |
|---|---|
| โ | โ |
| โ | โ |
Example: