Difference between revisions of "Turtle.inspect"

From ComputerCraft Wiki
Jump to: navigation, search
(Clarified state)
Line 8: Line 8:
 
|desc=Returns the ID string and metadata of the block in front of the Turtle in a table format: <var>{ name = "modname:blockname", metadata = 0, state = {} }</var>.<br><br>
 
|desc=Returns the ID string and metadata of the block in front of the Turtle in a table format: <var>{ name = "modname:blockname", metadata = 0, state = {} }</var>.<br><br>
  
The "state" sub-table is only present in Minecraft 1.8+, and contains [[http://minecraft.gamepedia.com/Block_states blockstate]] info for  the block being inspected. For example, a log of wood's state table contains the keys "variant" (which may be set to eg "oak"), and "axis" (which may be set to eg "y", indicating an upright orientation).  
+
The "state" sub-table is only present in Minecraft 1.8+, and contains [http://minecraft.gamepedia.com/Block_states blockstate]]info for  the block being inspected. For example, a log of wood's state table contains the keys "variant" (which may be set to eg "oak"), and "axis" (which may be set to eg "y", indicating an upright orientation).  
 
|examples={{Example
 
|examples={{Example
 
|desc=If there is a block in front of the turtle, prints it's name and metadata.
 
|desc=If there is a block in front of the turtle, prints it's name and metadata.

Revision as of 23:23, 26 December 2015


Grid Redstone.png  Function turtle.inspect
Returns the ID string and metadata of the block in front of the Turtle in a table format: { name = "modname:blockname", metadata = 0, state = {} }.

The "state" sub-table is only present in Minecraft 1.8+, and contains blockstate]info for the block being inspected. For example, a log of wood's state table contains the keys "variant" (which may be set to eg "oak"), and "axis" (which may be set to eg "y", indicating an upright orientation).
Syntax turtle.inspect()
Returns boolean success, table data/string error message
Part of ComputerCraft
API turtle

Examples

Grid paper.png  Example
If there is a block in front of the turtle, prints it's name and metadata.
Code
local success, data = turtle.inspect()

if success then
  print("Block name: ", data.name)
  print("Block metadata: ", data.metadata)
end

Additional Notes

  • Returns false when there is nothing (air) in front of the Turtle.


See also