Jump to content




Turtle Question


  • You cannot reply to this topic
5 replies to this topic

#1 Loopin

  • Members
  • 31 posts

Posted 15 May 2012 - 09:24 PM

Have any way to only catch a defined item?

#2 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 15 May 2012 - 10:01 PM

You can give the turtle (put in some slot of the turtle) the block you want it to dig, then use the compare function to know if it's the block you want and if it is then dig it, otherwise it keeps looking, maybe droping any unwanted blocks.
Example:
local slot = 1 -- slot of the block to dig

local function isBlock()
  turtle.select(slot)
  return turtle.compare()
end

while true do
  if isBlock() then
    turtle.dig()
    turtle.forward()
  else
    turtle.turnRight()
  end
end
Of course, this has to be changed a lot to do something usefull, but I hope you get the idea of it.

#3 Loopin

  • Members
  • 31 posts

Posted 15 May 2012 - 10:06 PM

Hmm, i can do to dig, and if not is the item that i wanted, drop and keep digging until i find my item?

#4 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 15 May 2012 - 10:39 PM

Yes, you compare to see if it's the block, dig it, and if was not the correct one drop it. The compare function compares the item in the selected slot with the block in front of the turtle, that's why you have to compare and then dig.

#5 Loopin

  • Members
  • 31 posts

Posted 16 May 2012 - 12:10 AM

Okay, Thnks :P/>

#6 MathManiac

  • Members
  • 60 posts
  • LocationWashington, United States

Posted 18 May 2012 - 12:50 AM

heh, I use turtle.compare() myself. I'm thinking of using the comparison function for a path follower. eg. block 1 would be path block, and block 2 would be turn block, etc.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users