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

[LUA] [SOLVED] Turtle receiver code, end expected for while statement?

Started by rzp1029, 22 October 2012 - 05:15 PM
rzp1029 #1
Posted 22 October 2012 - 07:15 PM
http://pastebin.com/eQy1FZf1

Link to the pastebin, I get an error on line 38, saying end expected for while, even though I don't want the while ending at line 38? Any ideas? I'm new to Lua, so it's probably just operator error, but no amount of googling has helped so far. Here's exactly what you see when you run the code as it sits:

http://imgur.com/NqiMs

If anyone has any ideas, or knows what the problem is, it would be greatly appreciated!
PixelToast #2
Posted 22 October 2012 - 07:21 PM
too many ends
Ditto8353 #3
Posted 22 October 2012 - 07:22 PM
You don't need an end for each elseif
Should be simlar to:
if <expression> then
<block>
elseif <expression> then
<block>
end
Ditto8353 #4
Posted 22 October 2012 - 07:23 PM
you dont put end before elseifs
Beat me to it…
Also lines 15 and 25 I believe.
rzp1029 #5
Posted 22 October 2012 - 07:23 PM
The ends are there for the for loops, not the elseifs? Or do I not need one for the for loops?
PixelToast #6
Posted 22 October 2012 - 07:25 PM
turtle receive:

    rednet.open("right")
    while true do
	  event, id, text = os.pullEvent()
	  if event == "rednet_message" then
	    if text == "excavate" then
				    shell.run(""..text, "5")
	    elseif text == "go up" then
				    for x = 0, 5 do
				    if turtle.detectUp() then
						    turtle.digUp()
						    x=x+1
				    end
						    turtle.up()
				    end
				    end
	    elseif text == "go right" then
				    turtle.turnRight()
				    for x = 0, 5 do
				    if turtle.detect() then
						    turtle.dig()
				    end
						    turtle.forward()
						    x=x+1
				    end
				    turtle.turnLeft()
	    elseif text == "go left" then
				    turtle.turnLeft()
				    for x = 0, 5 do
				    if turtle.detect() then
						    turtle.dig()
				    end
						    turtle.forward()
						    x=x+1
				    end
				    turtle.turnRight()
	    elseif text == "go down" then
				    for x = 0, 5 do
				    if turtle.detectDown() then
						    turtle.digDown()
				    end
						    turtle.down()
						    x=x+1
				    end
	
	    elseif text == "go back" then
				    turtle.turnRight()
				    turtle.turnRight()
				    for x = 0, 5 do
				    if turtle.detect() then
						    turtle.dig()
				    end
						    turtle.forward()
						    x=x+1
				    end
	
				    turtle.turnLeft()
				    turtle.turnLeft()
    end
end
Ditto8353 #7
Posted 22 October 2012 - 07:26 PM
The ends are there for the for loops, not the elseifs? Or do I not need one for the for loops?
You have 'end's instead of 'else's :3
21, 32, 42, 53
rzp1029 #8
Posted 22 October 2012 - 07:34 PM
Ah, I see what you mean now, thanks for the assist!
Ditto8353 #9
Posted 22 October 2012 - 07:36 PM
Good job super-team