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
component:debug [2018/03/12 12:17]
kiritow [World Object]
component:debug [2020/05/22 21:43] (current)
forecaster [Component: Debug]
Line 8: Line 8:
  
 The debug card's "​container"​ refers to the robot, computer or tablet with a debug card installed in it. The debug card's "​container"​ refers to the robot, computer or tablet with a debug card installed in it.
 +
 +On a dedicated server the debug card must be bound to a player by shift-right-clicking with it to run commands using the runCommand callback. The bound player needs to have permission to use the command provided to runCommand.
  
 Callbacks: Callbacks:
Line 14: Line 16:
   Changes the component network'​s energy buffer by the specified delta.   Changes the component network'​s energy buffer by the specified delta.
 - `connectToBlock(x:​number,​ y:number, z:​number):​boolean`  ​ - `connectToBlock(x:​number,​ y:number, z:​number):​boolean`  ​
-  Connect the debug card to the block at the specified coordinates.+  Connect the debug card to an opencomputers-compatible ​block at the specified coordinates.
 - `getPlayer(name:​string):​userdata`  ​ - `getPlayer(name:​string):​userdata`  ​
   Get the entity of a player.   Get the entity of a player.
Line 31: Line 33:
 - `isModLoaded(name:​string):​boolean`  ​ - `isModLoaded(name:​string):​boolean`  ​
   Get whether a mod or API is loaded.   Get whether a mod or API is loaded.
-- `runCommand(command:​string):​number` ​  +- `runCommand(command:​string):​number, string`   
-  Runs an arbitrary command using a fake player.+  Runs an arbitrary command using a fake player. The first return value will be 1 if the command ran successfully,​ or 0 otherwise. The second return value will contain what the command returned, or an error message. If the command doesn'​t return anything, such as /me, the second value will be nil.
 - `test():​userdata`  ​ - `test():​userdata`  ​
   Test method for user-data and general value conversion.   Test method for user-data and general value conversion.
Line 41: Line 43:
 - `sendToClipboard(player:​string,​ text:​string)`  ​ - `sendToClipboard(player:​string,​ text:​string)`  ​
   Sends text to the specified player'​s clipboard if possible.   Sends text to the specified player'​s clipboard if possible.
 +- `scanContentsAt(x:​ number, y: number, z: number[, worldId: number]):​boolean,​ string, table`  ​
 +  Returns contents at the location in world by id (defaults to host world). This method behaves the same as the move check for the robot and drone. The first return value is a boolean indicating whether a robot or drone would be able to enter the location (true means it would be blocked and cannot move into that space). The second return is a string value short name of the type of obstruction. Possible values here include: EntityLivingBase,​ EntityMinecart,​ air, liquid, replaceable,​ passable, and solid.The final value returned is a serialized or table representation of the entity or block scanned at the location. The following code snippet can be used to debug what is possibly blocking the robot from moving forward, if the robot is facing in the negative x direction.
 +
 +<code lua>
 +local debug = require("​component"​).debug
 +local serialize = require("​serialization"​).serialize
 +local x, y, z = debug.getX, debug.getY, debug.getZ
 +local offset_x = -1
 +local offset_z = 0
 +local blocking, label, content = debug.scanContentsAt(x() - .5 + offset_x, y() - .5, z() - .5 + offset_z)
 +print(blocking,​ label, serialize(content))
 +</​code>​
  
 ==== World Object ==== ==== World Object ====
Line 100: Line 114:
 - `setTileNBT(x:​number,​ y:number, z:number, nbt:​table):​boolean`  ​ - `setTileNBT(x:​number,​ y:number, z:number, nbt:​table):​boolean`  ​
   Set the NBT of the block at the specified coordinates.   Set the NBT of the block at the specified coordinates.
 +- `getBlockState(x:​number,​ y:number, z:number[, actualState:​boolean=false])`  ​
 +  Gets the block state for the block at the specified position, optionally getting additional display related data
  
 ==== Player Object ==== ==== Player Object ====