This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Neander_King's profile picture

How do I interpret turtle.inspect()?

Started by Neander_King, 25 January 2015 - 08:29 PM
Neander_King #1
Posted 25 January 2015 - 09:29 PM
So, I am trying to have a turtle check if a wood block is in front of it, and I know that turtle.inspect() returns a table with two items, one of which is the name, and another which is the ID. How would I get the value from turtle.inspect into a single variable?


local block = turtle.inspect()
print(block[1])

However, when I run that code, it returns the attempt to index ? error.
Quintuple Agent #2
Posted 25 January 2015 - 09:45 PM
turtle.inspect() returns a failed/success boolean then a table.

local didit,block = turtle.inspect()
if didit then print(block.name) else print("no block") end
This would return the name of the block infront of it
Neander_King #3
Posted 25 January 2015 - 09:47 PM
Thank you!