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

Exit program

Started by matejdro, 16 October 2012 - 03:03 PM
matejdro #1
Posted 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.
Doyle3694 #2
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
Ditto8353 #3
Posted 16 October 2012 - 05:13 PM
..but i want to return into shell…

return
matejdro #4
Posted 16 October 2012 - 05:16 PM
Thanks, error one works.

Ditto: only if you are not inside another function.
Ditto8353 #5
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.
Doyle3694 #6
Posted 16 October 2012 - 05:55 PM
erroring without reason is the most common and easy syntax to exit to shell I think
Ditto8353 #7
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.
Doyle3694 #8
Posted 16 October 2012 - 06:03 PM
haha <3
Cranium #9
Posted 16 October 2012 - 06:07 PM
You can also do shell.exit(shell.getRunningProgram())
faubiguy #10
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.
Cranium #11
Posted 16 October 2012 - 06:13 PM
Ah, you're right. But shell.exit() does exit the current program.
Ditto8353 #12
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.
faubiguy #13
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"
Doyle3694 #14
Posted 16 October 2012 - 06:29 PM
you forgot () in print :D/>/>
faubiguy #15
Posted 16 October 2012 - 06:32 PM
You can call print (or any function) without () if the only argument is a string literal.
Cloudy #16
Posted 16 October 2012 - 06:33 PM
you forgot () in print :D/>/>

Nope, he didn't. Lua supports that shortcut.
Ditto8353 #17
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…
Doyle3694 #18
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