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

Result of turtle.inspect()

Started by LuckyLuke, 22 July 2015 - 11:31 AM
LuckyLuke #1
Posted 22 July 2015 - 01:31 PM
Heyho,

what kind of return do i get after turtle.inspect?

My Function so far:


function IdentifyBlock(direction)
success = ""
data = ""

if direction == "up" then
  success, data = turtle.inspectUp()

elseif direction == "down" then
  success, data = turtle.inspectDown()

else
  success, data = turtle.inspect()
end

if success then
  print("|-- [BlockFound] Name: "..data.name)
  print("|-- [BlockFound] MetaName: "..data.metaname)
end
end

As an example: If there turtle is right in front of a Stone Block, what's the result of data.name and data.metaname?
Balthamel #2
Posted 22 July 2015 - 07:48 PM
Try print(turtle.inspect()) or variable = turtle.inspect() and examine what you have.
MKlegoman357 #3
Posted 22 July 2015 - 08:57 PM
Here's the wiki page for turtle.inspect(). You'd get this:


{
  name = "minecraft:stone",
  metadata = 0
}
Edited on 22 July 2015 - 06:58 PM
LuckyLuke #4
Posted 23 July 2015 - 09:39 AM
When i run this programm:


local success, data = turtle.inspect()
if success then
  print("Block name: ", data.name)
  print("Block metadata: ", data.metadata)
end


What can i see on screen?
For Example, a simple Stone-Block is placed in front of the turtle.
At this moment i cannot check on my CC-World, so i have to ask.
Edited on 23 July 2015 - 07:41 AM
flaghacker #5
Posted 23 July 2015 - 10:46 AM
I think name will be "minecraft:stone" and metadata will be 0.
Edited on 23 July 2015 - 08:47 AM
LuckyLuke #6
Posted 23 July 2015 - 11:02 AM
Thanks, exactly what i expected! :)/>
Well, what's the code for a minecraft:lavabucket?
I googled a while, but i didnt find a list of items with this code
Bomb Bloke #7
Posted 23 July 2015 - 11:29 AM
You can't "inspect" a lava bucket, as it's not a block. But if you had one in the turtle's inventory, you could get its name and damage using turtle.getItemDetail().
LuckyLuke #8
Posted 23 July 2015 - 11:42 AM
Ah, thanks! No idea why i didnt get that xD
Waitdev_ #9
Posted 23 July 2015 - 11:58 AM
if you place a block in front of it, it comes back

{"minecraft:stone",0}
i think.
MKlegoman357 #10
Posted 23 July 2015 - 01:15 PM
Here's a list that might help you.
Booyaah #11
Posted 23 July 2015 - 05:18 PM
Here's a function I wrote to get details of either a slot or block. It also uses the "name" to create a "mod" and "nickname" results.


function getDetails(slot) --returns details about that slot or block
  if slot=="down" or slot=="bottom" then
	result,details=turtle.inspectDown(slot)
  elseif slot=="up" or slot=="top" then
	result,details=turtle.inspectUp(slot)
  elseif slot=="forward" or slot=="front" then
	result,details=turtle.inspect(slot)
  elseif
	type(slot)~="number" then print("your getDetails arguement is not recognized")
  elseif type(slot)=="number" and math.floor(slot)>0 and math.floor(slot)<17 then
	details=turtle.getItemDetail(slot)
  else
	print("your getDetails arguement is not between 1 and 16")
  end

  if details then --delete this 'if' statement if you don't want nickname and mod
	details.mod=string.sub(details.name,1,string.find(details.name,":")-1)
	details.nickname=string.sub(details.name,string.find(details.name,":")+1)
  end

  if details then --delete this 'if' statement if you don't want it printed in the terminal
	print("name: "..details.name)
	if details.metadata then print("metadata: "..details.metadata) end
	if details.damage then print("damage: "..details.damage) end
	if details.nickname then print("nickname: "..details.nickname) end
	if details.mod then print("mod: "..details.mod) end
	if details.count then print("item count: "..details.count) end
  else
	print("ERROR")
  end
  return details
end

info=getDetails(7) --this is how you call the function and save the data

If your turtle is in front of a tree and you call this function with: info=getDetails("front") then you will see info printed on the terminal and you will get:
info.name="minecraft:log"
info.metadata=0
info.nickname="log"
info.mod="minecraft"

If you call this function with 64 red wool in slot 7: info=getDetails(7) then you get:
info.name="minecraft:wool"
info.damage=14
info.nickname="wool"
info.mod="minecraft"
info.count=64

I'm new to coding so there may be better ways to do what I'm doing but at least this works most of the time. It doesn't tell you if your slot is empty or if there is air where you are checking- that could be room for improvement.

Hope this helps.
-BOOYAAH
LuckyLuke #12
Posted 24 July 2015 - 08:30 AM
Awesome, thanks, i'll use the code in my programm :)/>