Instructions can be used singularly, or in groups. The current list of Robot Instructions are:
Assignment instructions set a given variable equal to some expression. Using this instruction, you can change both the globally defined variables as well as the robot's local variables.
The Do-While instruction is much like the While instruction, except the loop is executed first, and then the expression is checked.
Usage: If "(" Expression ")" Instructions [ "Else" Instructions ]
The If-Else conditional instruction is much like the If-Else "execute" statement, except you specify instructions instead of statements. See the if-else statement information for an example.
The iterate instruction allows you to have some set of instructions repeated a specific number of times, specified by Expression. For instance:
This instruction will make the specified robot move 4 squares in the direction it's facing. (Note: This is a random example, and the overall effect can be achieved using a more efficient statement such as 'move 4;'.)
The move instruction causes the specified robot to move a specified number of squares (defined using the above Expression) in the direction the robot is currently facing.
Note: If the robot moves such that it hits an object (another robot or block), the robot will be damaged and it will shut itself off. You can not revive the robot once it is damaged. Unless you know that the squares in front of your robot are not blocked, you should use a If-Else Robot Instruction coupled with a FrontIsClear Boolean Function, and some form of loop to move the robot forward safely. For instance, to move 4 squares forward, you can use:
iterate 4 times { if ( frontisclear ) move 1; }
This instruction will instruct the specified robot to take a beeper from the ground and place it in the robot's beeper bag. If there are no beepers on the ground, a warning is generated.
The PutBeeper Instruction will cause the specified robot to remove a beeper from its beeperbag and place it on the ground. If there are no beepers available, a warning is generated.
Each robot in RoBOTL is only allowed to change direction in 90° increments, in a counter-clockwise manner. The instruction to cause a robot to turn 90° is the turnleft instruction.
Note: Often, RoBOTL programs define 'turnright' as 'iterate 3 times turnleft;'.
Turns off the currently specified robot.
Turns on the currently specified robot.
Note: Robots which are damaged (by hitting an object) and are deactivated can NOT be re-activated by the turnon instruction.
One of the more powerful things you can do with RoBOTL is define your own instructions which you can use to instruct a robot to do something. The most typical user defined instruction is 'turnright'.
Example:
define { NewRobotType smart_bot { IsLikeA basic_bot; DefineNewInstruction turnright as iterate 3 times turnleft; } } execute { new smart_bot pete_bot; tell pete_bot : { move 1; turnleft; move 4; turnright; while ( frontisclear ) move 1; } }
This instruction will execute the given instructions as long as the expression is true. Note that the expression is checked before the first time through the while loop, so if the expression is initially false, the loop is ignored.