ComputerCraft Forums

ComputerCraft => Ask a Pro => Topic started by: TheTinyDeskEngineer on Mar 14, 2021, 05:29 PM

Title: turtle.inspect() is returning {nil, nil} while looking at oak log
Post by: TheTinyDeskEngineer on Mar 14, 2021, 05:29 PM
I'm trying to make an automatic tree farm with a felling turtle, and I need it to be able to distinguish between saplings and logs to chop, but when I place it to look at an oak log and save the table that the turtle.inspect() function returns to print it to figure out how to actually use the inspect function, when I run the program to print everything in the table, it prints:
nil
nil
How can I fix this?
Title: turtle.inspect() is returning {nil, nil} while looking at oak log
Post by: Lupus590 on Mar 14, 2021, 06:05 PM
Inspect only looks at the block directly infront of the turtle, i.e. the turtle needs to have it's front touching the block.
Title: turtle.inspect() is returning {nil, nil} while looking at oak log
Post by: TheTinyDeskEngineer on Mar 15, 2021, 07:12 PM
Quote from: Lupus590 on Mar 14, 2021, 06:05 PMInspect only looks at the block directly infront of the turtle, i.e. the turtle needs to have it's front touching the block.
Yes, I know, it's right in front of the oak log.
Title: turtle.inspect() is returning {nil, nil} while looking at oak log
Post by: Lupus590 on Mar 15, 2021, 10:23 PM
Can you screenshot your setup, post your code (use pastebin or similar if it's long) and say what version of the mod you are using.
Title: turtle.inspect() is returning {nil, nil} while looking at oak log
Post by: TheTinyDeskEngineer on Mar 18, 2021, 03:05 PM
The code I wrote was just to figure out how the inspect function works, so it's really short
local success, data = turtle.inspect()
print(data[1])
print(data[2])
sleep(3)
Title: turtle.inspect() is returning {nil, nil} while looking at oak log
Post by: Lupus590 on Mar 18, 2021, 04:12 PM
That's not what the data table looks like when inspecting a block with turtle.inspect. The table has non-numeric keys so asking for the first and second key will result in it being nil.

Try data.name.

You might also want to look at the serialised table to see what keys you can look at.

local success, data = turtle.inspect()
print(textutils.serialise(data))