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

Help with turtle block detection

Started by lordofttude, 16 December 2015 - 01:55 AM
lordofttude #1
Posted 16 December 2015 - 02:55 AM
I have tried to make a program that has the ability to only mine certain block types.

so far i have used this to do so :

function oreDetect()
if checkPriority() then
  print("Found a priority item")

  turtle.dig()
  turtle.forward()
  print("Item retrieved!")

  print("Checking for more on the right")
  turtle.turnRight()
  oreDetect()
  print("No more there")
  turtle.turnLeft()

  print("Checking for more on the left")
  turtle.turnLeft()
  oreDetect()
  print("No more there")
  turtle.turnRight()
end
end


function checkPriority()
priority = false
if turtle.detect() then

  turtle.select(12)
  if turtle.compare() == false then
   priority = true
  end
end
return priority
I did this for 3 slots for stone dirt and gravel respectively, but for some reason it does not work. I tried getting stone from the creative menu, I tried silk touching it, and even smelting it to see if this was a matter of weird meta datas, but that didn't work. If someone could tell me of an alternate way to do this, or what I'm doing wrong I would be really grateful :)/>.

function clear()
  oreDetect()
  turtle.dig()
end
Edited on 16 December 2015 - 02:39 AM
Bomb Bloke #2
Posted 16 December 2015 - 03:08 AM
Seeing the context in which this function is used would be helpful.
KingofGamesYami #3
Posted 16 December 2015 - 03:08 AM
I see nothing wrong with the snippet of code posted, it will do the same thing as this short example, except I added a print. If you are still having problems, please be more descriptive of the problem and post the entire code. I'd imagine you're incorrectly using the value returned by checkPriority.


turtle.select( 12 )
if not turtle.compare() then
  print( "This isn't the item in slot 12" )
end