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

Error During Program

Started by DragonDonut, 25 February 2012 - 06:46 PM
DragonDonut #1
Posted 25 February 2012 - 07:46 PM
Hi, I am experimenting around with making a miner that will mine a square straight down, but I get some errors…

when my turtle runs it it gets an error after some time, would be nice if annyone could try it out and look at the error message.

DragonDonut

Error message:

parallel:22: -9
press any key to continue
thread: java.lang.TreadDeath
mine:75: -2


Code:



local length = 0
local side = 0
local depth = 0
local turns = 0
local thing = 0
function mine()
	if not turtle.detect() and length == 0 then
		turtle.digDown()
		turtle.down()
	elseif turtle.detect() and length == 0 then
	end
end	
function turn()
	if length == 5 and side ~= 1 and thing == 0 then
			turtle.turnLeft()
			turtle.dig()
			turtle.forward()
			turtle.turnLeft()
			length = 0
			side = 1
			turns = turns + 1
			thing = 1
	elseif length == 5 and side ~=0 and thing == 1 then
			turtle.turnRight()
			turtle.dig()
			turtle.forward()
			turtle.turnRight()
			length = 0
			side = 0
			turns = turns +1
			thing = 0
	end
end
function mine2()
	while length ~= 5 do
			turtle.dig()
			turtle.forward()
			length = length + 1
	end
end
function down()
	if turns == 4 then
		turtle.digDown()
		turtle.down()
			if side == 1 then
				turtle.turnRight()
				turtle.turnRight()
				thing = 0
				side = 1
			elseif side == 0 then
				turtle.turnLeft()
				turtle.turnLeft()
				thing = 1
				side = 0
			else
				print("ERROR!!!")
			end
		turns = 0
		depth = depth + 1
		length = 0
	  
	end
  
end

while depth ~= 10 do
turn()
mine2()
down()
end

Casper7526 #2
Posted 25 February 2012 - 07:50 PM
We need the line # of the error
DragonDonut #3
Posted 25 February 2012 - 07:55 PM
line 75, but it doesn't come at once, it runs fore some time before a java error pops up… you should try it out to see what I mean
Liraal #4
Posted 25 February 2012 - 07:59 PM
can you paste the EXACT error message?
DragonDonut #5
Posted 25 February 2012 - 08:06 PM
Error message:
parallel:22: -9
press any key to continue
thread: java.lang.TreadDeath
mine:75: -2
Casper7526 #6
Posted 25 February 2012 - 08:10 PM
your code is pretty hard to read without "code" tags around it, but if your getting a thread error, that means your most likely running a recursive function

IE

function foo()
foo()
end
foo()
DragonDonut #7
Posted 25 February 2012 - 08:13 PM
Fixed the code tag thing…
DragonDonut #8
Posted 25 February 2012 - 08:25 PM
I changed a bit in the code over the last while loop and now I'm only getting the "parallel:22: -9" error
Casper7526 #9
Posted 25 February 2012 - 08:29 PM
When I ran your program with the code from the first time, I added some checks at the bottom and a small sleep too make sure it would never crash from not yielding



while depth ~= 10 do
sleep(.1)
print ("D"..depth)
print ("T"..turns)
print ("L"..length)
turn()
mine2()
down()
end

Both times that I ran the program it stopped responding at
D1
T0
L5
DragonDonut #10
Posted 25 February 2012 - 09:04 PM
I changed a bit in the code and now I don't get the error anymore, the turtle just miss behaves, but I'm working on that

New Code:


length = 0
side = 0
depth = 0
turns = 0
thing = false
function mine()
	if not turtle.detect() and length == 0 then
		turtle.digDown()
		turtle.down()
	elseif turtle.detect() and length == 0 then
	end
end	
function turn()
	if length <= 5 and side == 0 and thing == false then
			turtle.turnLeft()
			turtle.dig()
			turtle.forward()
			turtle.turnLeft()
			length = 0
			side = 1
			turns = turns + 1
			thing = false
	elseif length <= 5 and side == 1 and thing == true then
			turtle.turnRight()
			turtle.dig()
			turtle.forward()
			turtle.turnRight()
			length = 0
			side = 0
			turns = turns +1
			thing = true
	elseif side == 1 and thing == false then
		turtle.turnRight()
		turtle.dig()
		turtle.forward()
		turtle.turnRight()
		length = 0
		side = 0
		turns = turns + 1
		thing = true
	elseif side == 0 and thing == true then
		turtle.turnLeft()
		turtle.dig()
		turtle.forward()
		turtle.turnLeft()
		length = 0
		side = 1
		turns = turns +1
		thing = false
	print("S"..side)
	print(thing)
	end
end
function mine2()
	while length ~= 5 do
			turtle.dig()
			turtle.forward()
			length = length + 1
	end
end
function down()
	if turns == 4 then
		turtle.digDown()
		turtle.down()
			if side == 1 then
				turtle.turnRight()
				turtle.turnRight()
				thing = true
				side = 0
			elseif side == 0 then
				turtle.turnLeft()
				turtle.turnLeft()
				thing = false
				side = 1
			else
				print("ERROR!!!")
			end
		turns = 0
		depth = depth + 1
		length = 0
	  
	end
  
end

while depth ~= 11 do
sleep(.1)
print ("D"..depth)
print ("T"..turns)
print ("L"..length)
print("S"..side)
print(thing)
turn()
mine2()
down()
end