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

turtle.inspect block names and metadata

Started by BizzySleepin, 10 June 2015 - 08:25 PM
BizzySleepin #1
Posted 10 June 2015 - 10:25 PM
Hello Pros! I'm very new to ComputerCraft and programming in general and I have a quick question.

Ive made this little test program to learn how to use the turtle.inspect command but I am not sure how to use the block name and metadata in my program.


turtle.refuel()
local i = 1
repeat
block = turtle.inspectDown()
if block == true then
  turtle.digDown()
  turtle.suckDown()
  turtle.forward()
  print("broke, sucked, and moved")
  i = i + 1
else
  turtle.forward()
  print("no block, moved forward")
end
  i = i + 1
until i == 20

I only know how to use the true and false and not the name or metadata. So for an example I would like to be able to detect if the block is "minecraft:wheat" with metadata 7 meaning full grown.
Any help would be greatly appreciated! hopefully you dont see too much of me in the Ask a Pro section in the future :)/>
KingofGamesYami #2
Posted 11 June 2015 - 12:08 AM
turtle.inspectDown returns two variables, a boolean (true/false) and a table.

The table contains the keys name and metadata.

For instance, this will tell you what is below your turtle:


local success, t = turtle.inspectDown()
if success then
  print( "The block below your turtle is named " .. t.name .. " and has a metadata value of " .. t.metadata )
else
  print( "There isn't a block below your turtle" )
end
BizzySleepin #3
Posted 11 June 2015 - 09:41 PM
Thanks a lot man, i got it working. I will definitely try and read up on things a little more next time. I don't know how I missed that page haha

local block,type = turtle.inspectDown()
if type.name == "minecraft:wheat" then
Edited on 11 June 2015 - 07:42 PM