Jump to content




Result of turtle.inspect()



11 replies to this topic

#1 LuckyLuke

  • Members
  • 52 posts
  • LocationMinecraft

Posted 22 July 2015 - 12: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?

#2 Balthamel

  • Members
  • 86 posts

Posted 22 July 2015 - 06:48 PM

Try print(turtle.inspect()) or variable = turtle.inspect() and examine what you have.

#3 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 22 July 2015 - 07:57 PM

Here's the wiki page for turtle.inspect(). You'd get this:

{
  name = "minecraft:stone",
  metadata = 0
}

Edited by MKlegoman357, 22 July 2015 - 07:58 PM.


#4 LuckyLuke

  • Members
  • 52 posts
  • LocationMinecraft

Posted 23 July 2015 - 08: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 by LuckyLuke, 23 July 2015 - 08:41 AM.


#5 flaghacker

  • Members
  • 655 posts

Posted 23 July 2015 - 09:46 AM

I think name will be "minecraft:stone" and metadata will be 0.

Edited by flaghacker, 23 July 2015 - 09:47 AM.


#6 LuckyLuke

  • Members
  • 52 posts
  • LocationMinecraft

Posted 23 July 2015 - 10: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

#7 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 23 July 2015 - 10: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().

#8 LuckyLuke

  • Members
  • 52 posts
  • LocationMinecraft

Posted 23 July 2015 - 10:42 AM

Ah, thanks! No idea why i didnt get that xD

#9 Waitdev_

  • Members
  • 432 posts
  • LocationAdelaide

Posted 23 July 2015 - 10:58 AM

if you place a block in front of it, it comes back
{"minecraft:stone",0}
i think.

#10 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 23 July 2015 - 12:15 PM

Here's a list that might help you.

#11 Booyaah

  • Members
  • 9 posts

Posted 23 July 2015 - 04: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

#12 LuckyLuke

  • Members
  • 52 posts
  • LocationMinecraft

Posted 24 July 2015 - 07:30 AM

Awesome, thanks, i'll use the code in my programm :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users