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

[LUA]Mining Turtle Program

Started by Erik9519, 05 January 2013 - 10:52 PM
Erik9519 #1
Posted 05 January 2013 - 11:52 PM
Hi guys,
I'm triying to make a program to make a mining turtle automaticly mining a predefined area but I'm having some issues like if I want to mine an area 5x5 it actually mine a 5x6

http://pastebin.com/re4yeHcc

Other problems are the commands that need to be written twice for it to take them and that this part

			UnloadLayer = UnloadLayer + 1
			if (UnloadLayer == UnloadTargetLayer) and (Layer ~= TargetLayer)  then
				Unload(1)
			elseif Layer == TargetLayer then
				Unload(0)
			else
				turtle.down()
				for i=0,1 do
					if turtle.detectDown() then
						turtle.digDown()
					end
					turtle.down()
				end
			end
seem to not execute at all.
Thanks in advance for anyone willing to help me.
ChunLing #2
Posted 06 January 2013 - 03:50 AM
Place debug prints before and after conditionals you believe should execute but don't.
Erik9519 #3
Posted 06 January 2013 - 06:31 AM
Yes I tested it again and it doesn't execute that part. It always does the last statement no matter what wich is:

   else
	   turtle.down()
	   for i=0,1 do
		   if turtle.detectDown() then
			   turtle.digDown()
		   end
		   turtle.down()
	   end
   end
ChunLing #4
Posted 06 January 2013 - 10:25 AM
Sorry, a debug print looks like this:
print(type(UnloadLayer),": ",UnloadLayer,type(UnloadTargetLayer),": ",UnloadTargetLayer,type(Layer),": ",Layer,type(TargetLayer),": ",TargetLayer)
You put it before the conditional that isn't working as you want and it helps you figure out why.

In this case, it is because UnloadLayer is a number and UnloadTargetLayer is a literal string that may or may not contain numeric characters depending on what the user entered.