Search code examples
for-loopluaminecraftcomputercraft

Problems diagnosing a "'name' expected" error


I have some code that takes input from the user, then mines the area defined by the input. I'm getting the following error on the second line in the snippet below:

bios:367: [string "ChunkMiner"]:2: 'name' expected

I can't seem to figure out what's causing it. Here is the code:

function ChunkMine(w,l,h)
    for (y=0,h) do
        turtle.digDown()
        turtle.down()
        for (z=0,l) do
            if (z%2 == 0 and z!=0) then
                turtle.turnRight()
                turtle.turnRight()
            else 
                turtle.turnLeft()
                turtle.turnLeft
            end
            for (x=0,w) do
                turtle.dig()
                turtle.forward()
            end
            if (z+1 == l) then
                turtle.forward()
                turtle.turnRight()
            end
        end
    end
end
w = io.read()
l = io.read()
h = io.read()
ChunkMine(w,l,h)

What is the problem? How can I fix this error?


Solution

  • for (y=0,h) do
    

    is invalid for loop syntax, remove the parenthesis:

    for y = 0, h do
    

    There is one other error in the code: != should be ~=.