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

[Question] turtle.detect()

Started by BigDaddy5XL, 05 December 2012 - 05:11 AM
BigDaddy5XL #1
Posted 05 December 2012 - 06:11 AM
Not sure where the issue is here. Hope someone can help. I, along with what appears to be hundreds of others, am working on a tree farm program. In an attempt to be thorough, I want the turtle to check each location and determine what is there in each spot and act accordingly.


-- Examine location and return what is there
function checkLocation()
   turtle.turnLeft() -- to look at location
   sleep(1)
   if turtle.detect() then
	  sleep(1)
	  turtle.select(15)  -- slot holding saplings
	  sleep(1)
	  if turtle.compare() then
		 print("There is a sapling here already.")
		 sleep(1)
		 return ("sapling")
	  end
	  sleep(1)
	  turtle.select(14) -- slot holding at least 1 log block
	  sleep(1)
	  if turtle.compare() then
		 print("There is a tree here already.")
		 sleep(1)
		 return ("tree")
	  end
	  print("I don't know what is here.")
	  sleep(1)
	  return("other")
   else  -- if nothing dectected
	  print("This space is available.")
	  sleep(1)
	  return ("nothing")
   end
end

My issue is this: The above code works, and works 99% accurately when I load my turtle with the saplings and logs of rubber trees from industrial craft. However the accuracy drops dramatically when the turtle is loaded with birch saplings and logs. When a turtle executes the compare using birch 85% of the comparisons are returned as "I don't know what is here". This happens when the turtle compares to saplings and trees both. I have not tried this with pine, redwood, or jungle trees yet.

My question: Why is "other" being returned when "sapling" or "tree" conditions are true?

P.S. The sleep() calls are there to keep the turtle from doing all of this too fast and returning unwanted results.
Orwell #2
Posted 05 December 2012 - 06:26 AM
If I'm not mistaken, the current version of ComputerCraft has problems with comparing blocks with same id but different metadata. I'm not sure how this manifests to your problem, but I'm sure it does.

Here is the thread where I read something about this: http://www.computercraft.info/forums2/index.php?/topic/6040-146ssp-turtlecompare-fails-with-leaf-blockitems/page__p__50544__hl__+pick%20+block__fromsearch__1#entry50544 .