1

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
6
  • Any help or comment is appreciated Commented Mar 9, 2014 at 6:37
  • You're missing end for the function Length() definition Commented Mar 9, 2014 at 9:49
  • @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? Commented Mar 9, 2014 at 16:41
  • @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 Commented Mar 9, 2014 at 17:38
  • @Schollii Ok I figured it out!, my code was fine after my last edit I forgot to put it on the turtle lol! Commented Mar 9, 2014 at 18:03

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I have revised my code, and replaced all while loops with repeat loops, please see if you know what is still wrong, I have changed the error that occurs in the question as well. Thank You for all your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.