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

[Lua][Help]

Started by NegaMax, 14 December 2012 - 06:16 AM
NegaMax #1
Posted 14 December 2012 - 07:16 AM
I'm very new to Lua, and am having trouble getting my mining turtle program to work. I wrote it to mine out a 2 block high space, of a size specified by the user. But when I run the program, I get an error "bios:338: [string "rect"]:37: '=' expected". Why does it tell me this? I have an '=' on that line! I had this problem before with another program I wrote where it told me " 'do' expected" when I already had one. What's going on?

Here's the code (I know the logic is somewhat convoluted, but that will be subject to later revision):


--Variables
print("Left?")
local left = io.read()
print("Right?")
local right = io.read()
print("Forward?")
local front = io.read()
print("Backward?")
local back = io.read()
print("Up?")
local up =io.read()
print("Down?")
local down = io.read()

--Mining
turtle.turnRight()
turtle.digUp()
for i = 0, right-1 do
  turtle.dig()
  while not turtle.forward() do
    os.sleep(.25)
  end
  turtle.digUp()
end
turtle.turnleft()
for i = 0, front-1 do
  turtle.dig()
  while not turtle.forward() do
   os.sleep(.25)
  end
  turtle.digUp()
end
turtle.turnLeft()
turtle.turnLeft()
for i = 0, front+back-1 do
  turtle.dig()
  while not turtle.forward() do
  os.sleep(.25)
  end
  turtle.digUp()
end
turtle.turnRight()
x = 1
for j = 0, right+left-1 do
  turtle.dig()
  while not turtle.forward() do
  os.sleep(.25)
  end
  turtle.digUp()
  if ( x % 2 ) == 0 then
		turtle.turnLeft()
  else
		turtle.turnRight()
  end
  for i = 0, front+back-1 do
		turtle.dig()
        while not turtle.forward() do
          os.sleep(.25)
        end
		turtle.digUp()
  end
  x = x+1
  if ( x % 2 ) == 0 then
		turtle.turnLeft()
  else
		turtle.turnRight()
  end
end
FUCKCOMPUTERCRAFT!"£ #2
Posted 14 December 2012 - 07:37 AM
Do the for loops not need "==" and not "=" ??
NegaMax #3
Posted 14 December 2012 - 07:43 AM
I changed them, but now it returns the error "bios:338: [string "rect"]:18: '=' or 'in' expected". Hmmm…
BrolofTheViking #4
Posted 14 December 2012 - 09:16 AM
Except for the up and down functionality, which is asked for in the input, your program works perfectly fine for me (except that you left out the t in your first two print statements.) I have only one change I suggest you make, and that is to replace any instance of

turtle.forward()
with

while not turtle.forward() do os.sleep(.25) end
which will cause the turtle to repeatedly attempt to move forward (with a short delay between each one to avoid unnecessary processes) until it succeeds in moving forward, which will avoid it messing up on it's count of how many blocks it has gone if it runs into a player or mob or something else stops it from being able to move.
NegaMax #5
Posted 14 December 2012 - 03:13 PM
Thanks for the advice, it makes more senseto do it that way. But I still get the same error, "bios338: [string "rect"]:43: '=' expected". This is really starting to bother me, I don't see the problem
Lyqyd #6
Posted 14 December 2012 - 03:22 PM
Paste the new code. Make sure it's copied and pasted, not retyped. If you do have to retype it, be sure to verify each character is the same, since if you are retyping, the problem is most likely cause by an error that you're correcting as you copy without realizing it's there.
NegaMax #7
Posted 14 December 2012 - 03:39 PM
Thanks for the advice, works perfectly now! :)/>