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

Mining Turtle Code Not Working

Started by PixelatedTechnology, 20 December 2014 - 07:17 PM
PixelatedTechnology #1
Posted 20 December 2014 - 08:17 PM
Note: I am using Tekkit Classic, so any fixes after ComputerCraft 1.33 do not help

Hello, I am having a bit of trouble trying to get a program to work. The program is supposed to go foward until it hits something, detect what the block is, and if it is a…

…tree - chop it down
…sapling - go over it
…stone - turn around
…sandstone - turn around and stop


function chop() --Creates the function chop() for the wood chopping algorithm.
	 turtle.dig()
	 turtle.digUp()
	 turtle.up()
end
function over() --Creates the function over() for skipping that block.
	 turtle.up()
	 turtle.forward()
	 turtle.forward()
	 turtle.down()
end
function around() --Creates the function around() for turning around
	 turtle.turnLeft()
	 turtle.turnLeft()
end
function stop() -- Shortens the shutdown command to just "stop()"
	 os.shutdown()
end
while true do
	 while not turtle.detect() do --Goes forward until it reaches something in its path
		 turtle.forward()
	 end
	
	 turtle.select(1) --Selects Sapling
	
	 if turtle.compare() then
		 over()	
	 end
	
	 turtle.select(2) --Selects Wood
	
	 if turtle.compare() then
		 while turtle.compare() do --Wood chopping algorithm.
			 chop()
		 end
		 while not turtle.detectDown() do --Goes down until it reaches the ground.
			 turtle.down()
		 end
		 turtle.select(1) --Selects and places sapling.
		 turtle.place()
		 over()
	 end
	 turtle.select(3) --Selects Stone
	
	 if turtle.compare() then
		 around()
	 end
  
	 turtle.select(4) --Selects Sandstone (Stopping Block)
  
	 if turtle.compare() then
		 around()
		 stop()
	 end
end



Note: The server I am on is set so turtles do not need fuel

What it is doing is when it hits a sapling, occasionally it will just stop and scroll through the first 4 items, skipping the detect function completely. The only way I have found to fix it is by changing the block in front of it (breaking the sapling, growing the tree, etc.).

I really want to know how to fix this problem.
Lyqyd #2
Posted 20 December 2014 - 09:09 PM
Saplings change their metadata as they grow, so the first time that happens, ComputerCraft's compare command can no longer return true when comparing against them. You would have to check the other three, and if it isn't one of those, assume it's a sapling.