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 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.
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.
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.
Robots are capable of complex movements, but some you may want to understand some nuances.
Robots have a flight-height limitation. The general movement rules for robots go like this:
flightHeight above a solid block are valid (limited flight capabilities, default is 8).
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.
robot.name(): stringrobot.detect(): boolean, stringtrue if the robot if whatever is in front of the robot would prevent him from moving forward (a block or an entity) (Note: Drones return true even if the block is passable), false otherwise. The second parameter describes what is in front in general and is one of either entity, solid, replaceable, liquid, passable or air.robot.detectUp(): boolean, stringrobot.detect() except that it scans the block directly above the robot.robot.detectDown(): boolean, stringrobot.detect() except that it scans the block directly below the robot.robot.select([slot: number]): numberrobot.inventorySize(): numberrobot.count([slot: number]): numberrobot.space([slot: number]): numberrobot.transferTo(slot: number[, count: number]): booleantrue if exchanging the content between those slots was successful, false otherwise.robot.compareTo(slot: number): booleantrue if the item type in the specified slot and the currently selected slot are equal, false otherwise.robot.compare(): booleanrobot.detect() beforehand to determine if there is actually a block in front of the robot.robot.compareUp(): booleanrobot.compare just for the block directly above the robot.robot.compareDown(): booleanrobot.compare just for the block directly below the robot.robot.drop([count: number]): booleandropDown for that case. This method, drop, will drop the items to the front.true if at least one item was dropped, false otherwise.robot.use function to interact with those types of blocks.robot.dropUp(): booleanrobot.drop just for the block directly above the robot.robot.dropDown(): booleanrobot.drop just for the block directly below the robot.robot.suck([count: number]): booleantrue if at least one item was picked up, false otherwise.robot.drop and will interact with item inventories in the same way. However this will only take the first item available in that inventory. For more precise inventory management you need to install an inventory controller upgrade into the robot.false.robot.suckUp([count: number]): booleanrobot.suck except that it tries to pick up items from directly above the robot.robot.suckDown([count: number]): booleanrobot.suck except that it tries to pick up items from directly below the robot.robot.place([side: number[, sneaky: boolean]]): boolean[, string]true the robot will simulate a sneak-placement (like if the player would be using shift during placement), which is usually not necessary and only included for compatibility to other mods.true if an item could be placed, false otherwise. If placement failed, the secondary return parameter will describe why the placement failed.robot.placeUp([side: number[, sneaky: boolean]]): boolean[, string]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]robot.place except that the robot tries to place the item into the space directly below it.robot.durability(): number, number, number or nil, stringnil and an error message describing why no durability could be returned. The error message is one of no tool equipped or tool cannot be damaged.robot.swing([side: number, [sneaky:boolean]]): boolean[, string]robot.swingUp([side: number, [sneaky:boolean]]): boolean[, string]robot.swing except that the block or entity directly above the robot will be the target.robot.swingDown([side: number, [sneaky:boolean]]): boolean[, string]robot.swing except that the block or entity directly below the robot will be the target.robot.use([side: number[, sneaky: boolean[, duration: number]]]): boolean[, string]true the robot will simulate a sneak-right-click (like if the player would be using shift during a right-click). Some items (like buckets) will behave differently if this is set to true.block_activated - a block was activated (like levers, switches or doors).item_interacted - the equipped tool interacted with the world, for example sheers when used on a sheep.item_placed - something was placed into the world. This is not only caused by placeable blocks, but as well by items that cause blocks or entities to appear in the world (like flint and stone or mob eggs).item_used - the equipped was activated, like a splash-potion.air - the equipped item requires a target but there was none. Note that if your robot has an Angel upgrade, this will never be returned, however some actions might still cause no effect.robot.useUp([side: number[, sneaky: boolean[, duration: number]]]): boolean[, string]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]robot.use except that the item is used aiming at the area below the robot.robot.forward(): boolean[, string]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.robot.back(): boolean[, string]robot.forward() except that the robot tries to move backward.robot.up(): boolean[, string]robot.forward() except that the robot tries to move upwards.robot.down(): boolean[, string]robot.forward() except that the robot tries to move downwards.robot.turnLeft()robot.turnRight()robot.turnLeft except that the robot turns 90° to the right.robot.turnAround()robot.turnRight twice.robot.level(): numbercomponent.experience.level() instead (only available if the experience upgrade is installed).1.5, then the robot is level one, and 50% towards achieving level two.robot.tankCount():numberrobot.selectTank(tank)robot.tankLevel([tank:number]):numberrobot.tankSpace():numberrobot.compareFluidTo(tank:number):booleanrobot.transferFluidTo(tank:number[, count:number]):booleanrobot.compareFluid():booleanrobot.compareFluidUp():booleancompareFluid, but operates on the block above the robot.robot.compareFluidDown():booleancompareFluid, but operates on the block below the robot.robot.drain([count:number]):booleanrobot.drainUp([count:number]):booleandrain, but operates on the block above the robot.robot.drainDown([count:number]):booleandrain, but operates on the block below the robot.robot.fill([count:number]):booleanrobot.fillUp([count:number]):booleanfill, but operates on the block above the robot.robot.fillDown([count:number]):booleanfill, but operates on the block below the robot.