This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Exit program
Started by matejdro, 16 October 2012 - 03:03 PMPosted 16 October 2012 - 05:03 PM
Is there a function to terminate program? I know os.shutdown() kinda does it, but i want to return into shell, not shut down computer.
Posted 16 October 2012 - 05:06 PM
error(reason)
You don't need to put in a reason, if you don't put in one then it will say nothing, else it will print your reason with some "random"(I know it's not random but not to care about) text
Posted 16 October 2012 - 05:13 PM
..but i want to return into shell…
return
Posted 16 October 2012 - 05:16 PM
Thanks, error one works.
Ditto: only if you are not inside another function.
Ditto: only if you are not inside another function.
Posted 16 October 2012 - 05:21 PM
It is generally bad practice to raise an error "just because". Your program should be able to gracefully shutdown when it reaches a point which requires it.
Having multiple exit points in a program or even just a function opens the program to additional bugs and further obfuscates your code.
P.S. It's not my code. Do what you want.
Having multiple exit points in a program or even just a function opens the program to additional bugs and further obfuscates your code.
P.S. It's not my code. Do what you want.
Posted 16 October 2012 - 05:55 PM
erroring without reason is the most common and easy syntax to exit to shell I think
Posted 16 October 2012 - 06:01 PM
erroring without reason is the most common and easy syntax to exit to shell I think
Lets go back to talking about tables. We disagree less with tables.
Posted 16 October 2012 - 06:03 PM
haha <3
Posted 16 October 2012 - 06:07 PM
You can also do shell.exit(shell.getRunningProgram())
Posted 16 October 2012 - 06:11 PM
You can also do shell.exit(shell.getRunningProgram())
That will just cause the shell itself to shutdown after the running program exits by itself. shell.exit doesn't take any arguments.
Posted 16 October 2012 - 06:13 PM
Ah, you're right. But shell.exit() does exit the current program.
Posted 16 October 2012 - 06:15 PM
You can also do shell.exit(shell.getRunningProgram())
That will just cause the shell itself to shutdown after the running program exits by itself. shell.exit doesn't take any arguments.
Holy crap I learn so much in this place. Most of the people here are awesome. Thanks.
Posted 16 October 2012 - 06:23 PM
Ah, you're right. But shell.exit() does exit the current program.
Didn't work. I used:
shell.exit()
print "It didn't work"
Posted 16 October 2012 - 06:29 PM
you forgot () in print :D/>/>
Posted 16 October 2012 - 06:32 PM
You can call print (or any function) without () if the only argument is a string literal.
Posted 16 October 2012 - 06:33 PM
you forgot () in print :D/>/>
Nope, he didn't. Lua supports that shortcut.
Posted 16 October 2012 - 06:34 PM
You can call print (or any function) without () if the only argument is a string literal.
print {"Also tables","Woo!"}
…love me some tables…Posted 16 October 2012 - 06:40 PM
Well I learned something new this day, just like the previous…*checks when I registered cc forums*.. 23 days