295 posts
Location
In the TARDIS at an unknown place in time.
Posted 21 January 2013 - 09:15 AM
Well here's what's happening.. I have a
while true do thingy that contains an if statement and when I add
break to the code, it has this error:
bios:338: [string "mdm"]:362: 'end' expected (to close 'if' at line 360)
But I already have an end to close the if! Here's my statement:
while true do
if menucont == "host" then
break
goroutine.kill("Button2")
goroutine.kill("Button3")
host()
elseif menucont == "connect" then
break
goroutine.kill("Button1")
goroutine.kill("Button3")
connect()
elseif menucont == "quit" then
break
goroutine.kill("Button1")
goroutine.kill("Button2")
term.clear()
term.setCursorPos(1, 1)
end
sleep(0.1)
end
7508 posts
Location
Australia
Posted 21 January 2013 - 09:19 AM
Using break will immediately exit the loop and ignore any of the lines in the if statement after it. The compiler may be picking up on this.
48 posts
Location
Colorado, USA
Posted 21 January 2013 - 09:19 AM
It would help if you could post the whole code or add a pastebin link to it. Another alternative is adding indenting to your code (ie: spacing your if statement in a few spaces) and putting the code into notepad++. It highlights the code for you and helps determine what's wrong.
*Edit* sorry if that came off a bit rude or anything, I just didn't see anything wrong with the code so I figured it was somewhere else that had the issue.
295 posts
Location
In the TARDIS at an unknown place in time.
Posted 21 January 2013 - 09:21 AM
Using break will immediately exit the loop and ignore any of the lines in the if statement after it. The compiler may be picking up on this.
Oh, but still.. why am I getting that error? I've closed that if statement.
318 posts
Location
Somewhere on the planet called earth
Posted 21 January 2013 - 09:22 AM
"For syntax reasons break can only appear at end of a block"
http://www.lua.org/pil/4.4.html
295 posts
Location
In the TARDIS at an unknown place in time.
Posted 21 January 2013 - 09:25 AM
"For syntax reasons break can only appear at end of a block"
http://www.lua.org/pil/4.4.html
Oh! That makes so much more sense now.. thanks!
7508 posts
Location
Australia
Posted 21 January 2013 - 09:42 AM
putting the code into notepad++. It highlights the code for you and helps determine what's wrong.
The forums code tags don't like it when the code is already colored.
2005 posts
Posted 21 January 2013 - 02:17 PM
In the case of notepad++, the coloring has no effect on the text.