Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
api:robot [2018/09/27 01:39]
payonel
api:robot [2019/04/30 09:31]
meph old revision restored (2018/09/27 03:16)
Line 1: Line 1:
 ====== Robot API ====== ====== Robot API ======
 This API wraps the functionality of the **component** [[component:​robot|robot]] to allow more intuitive interaction with the robot. This API wraps the functionality of the **component** [[component:​robot|robot]] to allow more intuitive interaction with the robot.
 +
 +This is the api you are using when in your lua code you call
 +
 +<code lua>
 +local robot_api = require("​robot"​)
 +robot_api.forward()
 +</​code>​
 +
 +As opposed to using the robot component api directly, via the component interface
 +
 +<code lua>
 +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)
 +</​code>​
  
 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. 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.
Line 9: Line 24:
  
 ==== Slot alignment ==== ==== 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.  +{{page>​component:inventory_slots&​noheader&​nofooter}}
- +
-{{api:robot_slotalign.png}} +
- +
-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. +
 ==== Movement ==== ==== Movement ====
  
Line 86: Line 96:
 As `robot.compare` just for the block directly below the robot. As `robot.compare` just for the block directly below the robot.
 - `robot.drop([count:​ number]): boolean`  ​ - `robot.drop([count:​ number]): boolean`  ​
-Tries to drop items from the currently selected inventory slot in front of the robot.  ​+Tries to drop items from the currently selected inventory slot in **front** of the robot. Note that if you are trying to drop items into an inventory below you, this is the wrong method. Use `dropDown` for that case. This method, `drop`, will drop the items to the **front**.  ​
 **count** - specifies how many items to drop. If omitted or if count exceeds the amount of items in the currently selected slot, then all items in the currently selected slot are dropped.  ​ **count** - specifies how many items to drop. If omitted or if count exceeds the amount of items in the currently selected slot, then all items in the currently selected slot are dropped.  ​
 **Returns** `true` if at least one item was dropped, `false` otherwise.  ​ **Returns** `true` if at least one item was dropped, `false` otherwise.  ​
Line 200: Line 210:
 - `robot.fillDown([count:​number]):​boolean`  ​ - `robot.fillDown([count:​number]):​boolean`  ​
   Like `fill`, but operates on the block below the robot.   Like `fill`, but operates on the block below the robot.
-  ​+
 Contents Contents
 ----------- -----------
 {{page>​api:​contents&​noheader&​noeditbutton&​nouser&​nofooter}} {{page>​api:​contents&​noheader&​noeditbutton&​nouser&​nofooter}}