if( test )
Parameters
| Type | Description | |
| test | boolean | expression to check for true |
_result
Not set.
Descriptions
The if statement is not actually a robot command, but rather a way to control which robot instructions are run. An if line marks the beginning of a block of instructions. The block of instructions must be closed with an endif, elseif or else line. If statements may be nested.
When an if statement is run the test expression is evaluated. When test evaluates to true, the block of code following the if statement is executed. If test evaluates to false, the block of code immediately following the if statement is skipped. When test is false, execution continues at the next elseif, else, or endif line.
In the example below the block of code between the if and endif line is only run when _energy is greater than 25. When _energy is less than or equal to 25 execution jumps directly from the if to the endif line. The code block is indented only to highlight the logic group of instructions that go together. The game itself ignores spacing.
condition →
action
_energy == 40 →
fire( 7 )
_energy == 10 → nothing
See Also