1
votes

I have created a small program that asks for the length width and heights that you wish a mining turtle to mine. When I run it in the advanced computer though, It lets me prompt for the length, width and height but then I get an error. The error is as follows:

miner:39: attempt to index ? ( a nil value)

Here is my code:

term.clear()
term.setCursorPos(1,1)





write("Length:")
length = read()
print()
write("Confirm:")
ul = read()
print()

write("Width:")
width = read()
print()
write("Confirm:")
uw = read()
print()

write("Height:")
height = read()
print()
write("Confirm:")
uh = read()
print()

local totcount = ul + uw + uh
local subcount = 0




function Length()

repeat 

    turtle.dig()
    turtle.forward()
    length = length - 1
    subcount = subcount + 1

until length == 0
length = ul

end

function Width()

repeat

    turtle.dig()
    turtle.forward()
    width = width - 1
    subcount = subcount + 1

until width == 0
width = uw
end

function Height()
turtle.digDown()
turtle.down()
height = height - 1
subcount = subcount + 1
end

function Turn()

turtle.turnRight()

end



repeat

Length()
Turn()
Width()
Turn()
Length()
Turn()
Width()
Turn()
Height()

until subcount == totcount
1
Any help or comment is appreciated - cmd
You're missing end for the function Length() definition - hjpotter92
@Schollii I have revised my code, I do not quite understand what you said about the while loop, if you can, will you post some code? - cmd
@hjpotter92 @ Schollii I have once more revised my code, instead of while loops I used repeat loops, yet now CC is telling me that I am indexing a nil value, Please re-read my question Thank You - cmd
@Schollii Ok I figured it out!, my code was fine after my last edit I forgot to put it on the turtle lol! - cmd

1 Answers

2
votes

It doesn't look any of your functions have end, fix that first. If you properly indent your code you will see this.

You also have while count < length do with an else block. AFAIK this is not valid syntax (never seen it and just checked online ref manual and wiki). It is not clear whether you meant if count < length do, but if really meant while then replacing else by end doesn't look right either. Take a closer look at that section of code.