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

[Lua][1.4][Error] :40: '<name>' expected

Started by Lettuce, 15 August 2012 - 05:21 AM
Lettuce #1
Posted 15 August 2012 - 07:21 AM
*sigh* I hate posting 2 questions about the same program. The last one was to learn how dan200 retrieved the turtle in the 'excavate' program, so I could make this program. I finished coding it, and in theory (experimental code) it should work. It's 205 lines long, (206, technically but I'll remove the 'line 40' comment later) and is the most complicated project I've ever worked on. I intend to add one more function, after debugging.
It will mine a user-defined section, and return items to a chest. Then, resume mining where it left off. I will be very happy when I finish it.

Skipping to the point, I am getting :bios:206 [string "mine"]:40: '<name>' expected.

I've never encountered this error, and that whole function should work fine. Since I added a comment showing where line 40 is, it's actually 41. If that matters.

CODE:
Spoiler

--declaring variables
print "This will mine a predefined pattern of blocks. Use after vertshaft or stairshaft."
print "All values are positive integers."
print "Fuel in 16"
print "How wide is this mine to be? (x) !MUST BE AN ODD NUMBER!"
x = io.read()
x = tonumber(x)
print "How far forward? (y)"
y = io.read()
y = tonumber(y)
y = y-1
print "How high? (z)"
z = io.read()
z = tonumber(z)
z = z-1
-- origins
xo = x/2
xo = math.ceil(xo)
-- sxo is used to find the turtle's start point. It is crucial that x be odd for this to work right.
sxo = xo
yo = 0
zo = 0
-- declaring functions
function checkFuel()
if turtle.getFuelLevel <= z*2+2 then
turtle.select(16)
turtle.refuel(1)
end
end
function moveForward()
checkFuel()
repeat
turtle.dig()
until turtle.forward()
end
--function containing line 40.
function mineUp()
for local i = 1,z do
  checkFuel()
  repeat
  turtle.digUp()
  until turtle.up()
  zo = zo+1
end
end
function mineDown()
repeat
checkFuel()
  repeat
  turtle.digDown()
  until turtle.down()
  zo = zo-1
until zo == 0
end
function check()
turtle.select(15)
if turtle.getItemCount >= 1 then
  local xpo = xo
  local ypo = yo
  turtle.select(1)
   if xo > xpo then
   turtle.turnLeft()
   turtle.turnLeft()
   repeat
   moveForward()
   xo = xo-1
   until xo == xpo
   end
   if xo < xpo then
   turtle.turnLeft()
   turtle.turnLeft()
   repeat
   moveForward()
   xo = xo+1
   until xo == xpo
   turtle.turnLeft()
   turtle.turnLeft()
   end
  turtle.turnLeft()
   repeat
   moveForward()
   yo = yo-1
   until yo == 0
   for t=1,15 do
   turtle.select(t)
   turtle.drop()
   end
  turtle.turnLeft()
  turtle.turnLeft()
  repeat
  moveForward()
  yo = yo+1
  until yo == ypo
  if xpo > sxo then
  turtle.turnLeft()
  repeat
  moveForward()
  xo = xo+1
  until xo == xpo
  if xpo < sxo then
  turtle.turnRight()
  repeat
  moveForward()
  xo = xo-1
  until xo = xpo
end
turtle.select(1)
end
--  setting up to align
turtle.turnLeft()
for local i = 1,xo do
moveForward()
mineUp()
  if x == 1 then
  mineDown()
  check()
  break
  end
moveForward()
mineDown()
check()
  if x == 3 then
  break
  end
moveForward()
end
turtle.turnLeft()
turtle.turnLeft()
mineUp()
mineDown()
check()
for local i = 1,xo do
moveForward()
end
for local i = 1,xo-1 do
mineUp()
  if x == 1 then
  mineDown()
  check()
  break
  end
moveForward()
mineDown()
check()
  if x == 3 then
  break
  end
moveForward()
end
-- and finally, on line 155, we have reached the main loop.
for local i = 1,y do
turtle.turnLeft()
moveForward()
yo = yo+1
turtle.turnLeft()
  for local a = 1,x do
  mineUp()
   if x == 1 then
   mineDown()
   check()
   break
   end
  moveForward()
  xo = xo+1
  mineDown()
  check()
  moveForward()
  xo = xo+1
  if x == 3 then
  mineUp()
  mineDown()
  check()
  break
  end
  end
turtle.turnRight()
moveForward()
turtle.turnRight()
yo = yo+1
  for local b = 1,x do
  mineUp()
   if x == 1 then
   mineDown()
   check()
   break
   end
  moveForward()
  xo = xo-1
  mineDown()
  check()
  moveForward()
  xo = xo-1
  if x == 3 then
  mineUp()
  mineDown()
  check()
  break
  end
  end
end

Thank you,
Lettuce
immibis #2
Posted 15 August 2012 - 07:40 AM

for local i = 1,z do
should be

for i = 1,z do

The "i" is automatically local since you're declaring it in a for loop
Xtansia #3
Posted 15 August 2012 - 07:42 AM
Remove the 'local from your for loop.
Lettuce #4
Posted 15 August 2012 - 07:51 AM
in the future, can you guys take longer? Make it seem like it's harder to find and I'm not a complete newb?
I'm just kiddin'. Thanks a lot.