Conditional Code
Onto more complex scripting! Conditional code is an important aspect of intermediate to advanced scripts.
Conditional code entails running a chunk of code if a boolean
condition evaluates to true
.
This allows you to execute code that can adapt to conditions in the world, the player, a block, or the entity that’s dropping items.
If Statement
An if statement executes the piece of code if the boolean
inside of its bracket evaluates to true
.
Else Statement
An else statement can be added to the end of an if statement to execute the block in case the if statement returns false, which means it did not execute.
Supported Operators
Supported operators you can do calculations with are: +
, -
, +
, /
, %
.
Keep in mind you can also use the logic operators: !
, !=
, ==
, >
, >=
, <
, <=
, &&
, ||
, ^
Apart from these, as long as whatever is inside of the if bracket returns true, you can have anything in there!
Example: