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

[Lua][Error]

Started by Mika811, 10 January 2013 - 06:37 AM
Mika811 #1
Posted 10 January 2013 - 07:37 AM
Hello everyone,

I'm kinda new to lua and did not coded really much but i know the basics.
I was trying to write a mining program in a (what i think is) effective and easy way.
But after i was done with writing and bugfixing it is still not working.
The goal was to let it mine away a 10 x 10 or 100 x 100 area but insteed it only digs out 10 blocks in the front.
I really can't find the problem myself, i tried many things.


x = 0
y = 10
q = true
z = 10
p = y
function mine()
turtle.dig()
turtle.digUp()
turtle.forward()
end

function mineLeft()
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.turnLeft()
q = false
z = z - 1
y = p
end

function mineRight()
turtle.dig()
turtle.forward()
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.turnRight()
q = true
z = z - 1
y = p
end

function compare()
select(2)
a = turtle.compare()
select(3)
b = turtle.compare()
select(4)
c = turtle.compare()
select(5)
d = turtle.compare()
select(6)
e = turtle.compare()
select(7)
f = turtle.compare()
select(8)
g = turtle.compare()
select(9)
h = turtle.compare()
select(10)
i = turtle.compare()
while a or b or c or d or e or f or g or h or i == true do
turtle.digDown()
turtle.down()
x = x + 1
o = false
end
end
function goBack()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
while x > 0 do
turtle.digUp()
turtle.up()
x = x - 1
end
y = y - 3
o = true
end

function needFuel()
if turtle.getFuelLevel() < 2000 then
return true
else
return false
end
end

function refuel()
turtle.refuel(1)
end

function test()
if y == 0 and q == true then
mineLeft()
return true
else return true
end
if y == 0 and c == false then
mineRight()
return true
else return true
end
if 0 == 10 then
goBack()
end
end

while needFuel() do refuel()
end


while test() and y > 0 and z > 0 do
compare()
mine()
y = y - 1
end 


I hope someone can help me with this problem!

Greetings,
Mika811
ChunLing #2
Posted 10 January 2013 - 09:26 AM
Here is your main program body:
while needFuel() do refuel()
end
while test() and y > 0 and z > 0 do
compare()
mine()
y = y - 1
end
See the problem?

Sorry, I should mention that, after you run compare(), c is boolean, and thus will never be equal to 5 or 10, which are numbers.
Edited on 10 January 2013 - 08:29 AM
Mika811 #3
Posted 10 January 2013 - 09:52 AM
Soo, if i'm right the compare function add a coolean to c without putting it in the code? And changing the letter should solve the problem
Nvm my wrong interpetation, i editted the code some and now it does turn once left but it does not continue afterwards and also does still not compare the ores.
(i updated the code)
ChunLing #4
Posted 10 January 2013 - 10:50 AM
You updated "if y == 0 and q == true then" but not "if y == 0 and c == false then". That makes the mineRight() call dependent on the last compare for c.

In the compare function, you have
while a or b or c or d or e or f or g or h or i == true do
turtle.digDown()
turtle.down()
x = x + 1
o = false
end
It's probably just as well that this never happens, because you don't provide any way for it to stop (nothing in the while loop changes the values of a,b,c,d,e,f,g,h,or i). But after you fix that somehow so it doesn't cause your turtle to dig down to bedrock, you should look at your slots and see if there would be any reason for turtle.compare() to return true for any of them.
crazyguymgd #5
Posted 10 January 2013 - 11:09 AM
Why is he only turning right if c is false?