Table of Contents

Robot API

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

This is the api you are using when in your lua code you call

local robot_api = require("robot")
robot_api.forward()

As opposed to using the robot component api directly, via the component interface

local component = require("component")
local robot_component_api = component.robot -- if using openos, else component.proxy(component.list("robot")())
robot_component_api.move(sides.front)

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.

Note that a Robot is also computer 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

Internal versus External Slot Alignment

Slot indexes do not match between the robot's internal and external view of its inventory

When a robot interacts with its own inventory it is using its internal view. You access the inventory of another robot via its external view.

The reason for this distinction is to separate the two inventory spaces: the main inventory and the tool belt inventory. Internally, the robot selects slots only in its inventory space, and not its toolbelt. It can equip or unequip items from its toolbelt. However, externally, an observer interacts with a single inventory that includes both the toolbelt as well as the main inventory.

Internal 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.

These are the slot indexes a robot uses on it self (for its own main inventory, an interview view).

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.

The robot can select, place, drop, compare (etc) items from its main inventory using these slot indexes as they represent the internal perspective of its inventory.

External View of a Robot Inventory

Slot indexes of a robot's inventory to an outside observer will be offset by 4. To an outside observer, slots 1 through 4 refer to slots in the robot toolbelt. The first slot of the main inventory is slot 1 from inside the robot (internal view), but is thus slot 5 to an outside observer. Yes, this can be confusing at first. This design choice was made so that, to an outside observer, [slot 1] always indicated the first toolbelt slot regardless of the robot inventory size, and [slot 5] was always the first main inventory slot.

The robot inventory, again to an external observer, is sided inventory. The robot will not share all its inventory to all sides. Slot indexes do not change to these different sides. Slot 1, therefore, always refers to the first toolbelt slot, even when inaccessible to a side.

  • From its left side it share nothing.
  • From its right side it shares only its toolbelt slots (1-5)
  • From all other sides it shares only its main inventory slots (5-n)

Movement

Robots are capable of complex movements, but some you may want to understand some nuances.

Hovering

Robots have a flight-height limitation. The general movement rules for robots go like this:

Violating these rules will result in a the error impossible move to be returned

You can install hover upgrades to increase (tier 1) and pretty much circumvent (tier 2) this limitation. Or you can disable this in the config, by setting limitFlightHeight to 256 or so.

source

API Exclusive Methods

Contents