8 posts
Posted 07 July 2013 - 02:11 PM
Hello!
I've been wondering that can you in lua, like in the Basic-language that I've learned (a bit)use a command that makes the program jump over lines or go back to the start of the program.
In Basic I would do like this:
Hello: –program name and a specific place in the program
Print "write hello" – prints write hello
Input x – waits for the user to input a variable
if x=hello then end
else goto Hello
In this case the problem could be solved with a loop but it's just an example
8543 posts
Posted 07 July 2013 - 02:17 PM
No, you just use a loop in Lua.
570 posts
Location
Germany
Posted 07 July 2013 - 02:21 PM
Nope you can't do that, but a you can make functions that can get called later in your program or even inside of itself. Also your program has some syntax errors that I can see.
131 posts
Posted 07 July 2013 - 03:14 PM
Not in Lua 5.1 (the version CC uses).
In Lua 5.2, you can use the `goto` statement like this:
::Hello:: --program name and a specific place in the program
print"write hello" -- prints write hello
x = io.read() -- waits for the user to input a variable
if x == "hello" then os.exit() else goto Hello end -- NOTE: You can normally have this on two lines,
-- but it won't work if you are typing it at an interactive Lua prompt.
However, as you stated, it would be easier to use a loop in this circumstance:
repeat
print"write hello"
x = io.read()
until x == "hello"
Edited on 07 July 2013 - 03:07 PM
8543 posts
Posted 07 July 2013 - 03:22 PM
Speaking of the version of Lua CC uses, it's easier to just use read(). Unless they added .stdin to ComputerCraft's io library in the beta, it doesn't exist, and io.read() just calls read() after stripping away any arguments passed to it.
131 posts
Posted 07 July 2013 - 05:08 PM
Speaking of the version of Lua CC uses, it's easier to just use read(). Unless they added .stdin to ComputerCraft's io library in the beta, it doesn't exist, and io.read() just calls read() after stripping away any arguments passed to it.
Sorry 'bout that. I normally code in Lua 5.2.2 and I'm an explicit sort of person. Post edited to fix.
8 posts
Posted 08 July 2013 - 04:50 AM
OK Thanks
(And yes I know there is some errors in the basic-code just didn't bother to fix them)