Difference between revisions of "Turtle.inspect"
From ComputerCraft Wiki
MKlegoman357 (Talk | contribs) (Created page with "{{lowercase}} {{Function |name=turtle.inspect |args=[<nowiki/>{{type|number}} slotNum] |api=turtle |returns={{type|boolean}} success, {{type|table}} data/{{type|string}} error...") |
Magiczocker (Talk | contribs) m |
||
| (8 intermediate revisions by 5 users not shown) | |||
| Line 2: | Line 2: | ||
{{Function | {{Function | ||
|name=turtle.inspect | |name=turtle.inspect | ||
| − | |args= | + | |args= |
|api=turtle | |api=turtle | ||
|returns={{type|boolean}} success, {{type|table}} data/{{type|string}} error message | |returns={{type|boolean}} success, {{type|table}} data/{{type|string}} error message | ||
|addon=ComputerCraft | |addon=ComputerCraft | ||
| − | |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 }</var>. | + | |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 [https://minecraft.gamepedia.com/Block_states block state] 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. | ||
| Line 19: | Line 21: | ||
* Returns false when there is nothing (air) in front of the Turtle. | * Returns false when there is nothing (air) in front of the Turtle. | ||
}} | }} | ||
| + | |||
| + | ==See also== | ||
| + | *[[turtle.inspectDown]] | ||
| + | *[[turtle.inspectUp]] | ||
| + | [[Category:API Functions]] | ||
Latest revision as of 07:59, 4 August 2020
| 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 block state 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
| 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.