turtle.inspect() is returning {nil, nil} while looking at oak log

Started by TheTinyDeskEngineer, Mar 14, 2021, 05:29 PM

Previous topic - Next topic

TheTinyDeskEngineer

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?

Lupus590

Inspect only looks at the block directly infront of the turtle, i.e. the turtle needs to have it's front touching the block.

TheTinyDeskEngineer

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.

Lupus590

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.

TheTinyDeskEngineer

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)

Lupus590

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))