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
cmd
  • 563
  • 3
  • 10
  • 26
  • Any help or comment is appreciated – cmd Mar 09 '14 at 06:37
  • You're missing `end` for the `function Length()` definition – hjpotter92 Mar 09 '14 at 09: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? – cmd Mar 09 '14 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 – cmd Mar 09 '14 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! – cmd Mar 09 '14 at 18:03
  • OK could you please accept an answer if worked. I was posting from my phone so could not post code but I'm glad to hear your code now works. Also you should probably change your question code back to what it was because now anyone reading it has no way of knowing what issue was. – Oliver Mar 10 '14 at 01:02

1 Answers1

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.

Oliver
  • 27,510
  • 9
  • 72
  • 103
  • 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. – cmd Mar 09 '14 at 17:45