**This is an old revision of the document!**

Robot API

This API wraps the functionality of the component robot to allow more intuitive interaction with the robot.

While the component robot has more generic functions like move([side: number]) or drop([side: number]), this API has more intuitive and failsafe functions like turnRight, dropDown, forward. Which one you use is up to you, you can even use both at the same time. Certain functions behave the same way regardless of how it's called, i.e. component.robot.name() and robot.name() return the same thing. Other functions behave slightly differently, i.e. robot.place() is the equivalent of component.robot.place(sides.front). The following page will summarize only the additional functions provided by the API, (the full API can be found in /lib/robot.lua).

Note that a Robot is an OpenComputer like any other with just an additional robot component included, so the normal APIs are available as usual.

See Robot Block for additional information on the actual Robot.

Slot alignment

The Robot's GUI displays the slots of a robot aligned from top-left to bottom-right. So for example the slot at index 1 is displayed in the top-left corner, the slot at index 2 is the next to the right and the first slot on the 2nd row is index 5.

How many slots a robot has available depends on it's setup. If a slot is specified in a function that exceeds the amount of slots a robot has available an error is thrown.

Callbacks:

  • robot.detectUp(): boolean, string
    As robot.detect() except that it scans the block directly above the robot.
  • robot.detectDown(): boolean, string
    As robot.detect() except that it scans the block directly below the robot.
  • robot.compareUp(): boolean
    As robot.compare just for the block directly above the robot.
  • robot.compareDown(): boolean
    As robot.compare just for the block directly below the robot.
  • robot.dropUp(): boolean
    As robot.drop just for the block directly above the robot.
  • robot.dropDown(): boolean
    As robot.drop just for the block directly below the robot.
  • robot.suckUp([count: number]): boolean
    As robot.suck except that it tries to pick up items from directly above the robot.
  • robot.suckDown([count: number]): boolean
    As robot.suck except that it tries to pick up items from directly below the robot.
  • robot.placeUp([side: number[, sneaky: boolean]]): boolean[, string]
    As robot.place except that the robot tries to place the item into the space directly above it.
  • robot.placeDown([side: number[, sneaky: boolean]]): boolean[, string]
    As robot.place except that the robot tries to place the item into the space directly below it.
  • robot.swingUp([side: number]): boolean[, string]
    As robot.swing except that the block or entity directly above the robot will be the target.
  • robot.swingDown([side: number]): boolean[, string]
    As robot.swing except that the block or entity directly below the robot will be the target.
  • robot.useUp([side: number[, sneaky: boolean[, duration: number]]]): boolean[, string]
    As robot.use except that the item is used aiming at the area above the robot.
  • robot.useDown([side: number[, sneaky: boolean[, duration: number]]]): boolean[, string]
    As robot.use except that the item is used aiming at the area below the robot.
  • robot.forward(): boolean[, string]
    Tries to move the robot forward.
    Returns: true if the robot successfully moved, nil otherwise. If movement fails a secondary result will be returned describing why it failed, which will either be 'impossible move', 'not enough energy' or the description of the obstacle as robot.detect would return.
    The result 'not enough energy' is rarely returned as being low on energy usually causes the robot to shut down beforehand.
    The result 'impossible move' is kind of a fall-back result and will be returned for example if the robot tries to move into an area of the world that is currently not loaded.
  • robot.back(): boolean[, string]
    As robot.forward() except that the robot tries to move backward.
  • robot.up(): boolean[, string]
    As robot.forward() except that the robot tries to move upwards.
  • robot.down(): boolean[, string]
    As robot.forward() except that the robot tries to move downwards.
  • robot.turnLeft()
    Turns the robot 90° to the left.
    Note that this can only fail if the robot has not enough energy to perform the turn but has not yet shut down because of it.
  • robot.turnRight()
    As robot.turnLeft except that the robot turns 90° to the right.
  • robot.turnAround()
    This is the same as calling robot.turnRight() twice.
  • robot.level(): number
    Deprecated since OC 1.3 use component.experience.level() instead (only available if the experience upgrade is installed).
    Returns the current level of the robot, with the fractional part being the percentual progress towards the next level. For example, if this returns 1.5, then the robot is level one, and 50% towards achieving level two.
  • robot.compareFluidUp():boolean
    Like compareFluid, but operates on the block above the robot.
  • robot.compareFluidDown():boolean
    Like compareFluid, but operates on the block below the robot.
  • robot.drainUp([count:number]):boolean
    Like drain, but operates on the block above the robot.
  • robot.drainDown([count:number]):boolean
    Like drain, but operates on the block below the robot.
  • robot.fillUp([count:number]):boolean
    Like fill, but operates on the block above the robot.
  • robot.fillDown([count:number]):boolean
    Like fill, but operates on the block below the robot.
    Contents