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

Lua Error w Mining Turtle w repeat loops

Started by Guard13007, 15 May 2012 - 09:26 PM
Guard13007 #1
Posted 15 May 2012 - 11:26 PM
I am trying to run the following code (which I don't see what is wrong with it):

print("Mine by Guard13007 (adv version of excavate that mines through anything)")
print("Pattern is right and and forward from current position.")
print()
write("Enter width: ")
sW = io.read()
nW = tonumber(sW)
print()
write("Enter length: ")
sL = io.read()
nL = tonumber(sL)
print()
write("Enter height: ")
sH = io.read()
nH = tonumber(sH)

z = 1
-- z is height up and down nH
repeat
print("Level "..z)
z=z+1

y = 1
-- y is width left to right nW
repeat
  print("Line "..y)
  y=y+1

  x = 1
  -- x is length front to back nL
  repeat
   x=x+1
   turtle.digDown()
   turtle.forward()
  until x >= nL

  test=y%2
  if test==1 then
   turtle.turnRight()
   turtle.forward()
   turtle.turnRight()
  else
   turtle.turnLeft()
   turtle.forward()
   turtle.turnLeft()
  end
until y >= nW

turtle.down()
if test==1 then
  --turn right and go back to start using width and turn right
  turtle.turnRight()
  y = 1
  repeat
   y=y+1
   turtle.forward()
  until y >= nW
  turtle.turnRight()
else
  --turn left and go back using width, turn left, use length to go back to start, turn left, turn left
  turtle.turnLeft()
  y = 1
  repeat
   y=y+1
   turtle.forward()
  until y >= nW
  turtle.turnLeft()
  x = 1
  repeat
   x=x+1
   turtle.forward()
  until x >= nL
  turtle.turnLeft()
  turtle.turnLeft()
end

until z >= nH

--go up
z = 1
repeat
z=z+1
turtle.up()
until z >= nH

print("Mining complete.")
exit()

I get this error when trying to run it:

[attachment=225:2012-05-15_14.54.07.png]

What's wrong?

An even better solution, can someone explain how to use the while loop? I can't seem to get it to work.

while i >= 5 do
i=i+5
--other stuff
end

That sort of thing always returns "expected "do"" I've tried with >= and => and > and none work (is it limited to == and ~=? that seems stupid to me if that is the problem, so that can't be the problem).
MysticT #2
Posted 15 May 2012 - 11:36 PM
The code seems to be ok, except for the exit() call at the end, there's no such function. It might be a typo in your code, did you copy this from the file or by hand?
The while syntax is correct, it would never end since you add 5 and check if it's higher than 5, but the syntax it's ok. Again, it might be a typo.