This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Exiting a program
Started by abihoooo, 21 February 2013 - 09:34 AMPosted 21 February 2013 - 10:34 AM
Is there a command to exit a program that brings you back to the command line like terminating? Something like shell.exit(), but not stopping the whole computer.
Posted 21 February 2013 - 10:39 AM
os.queueEvent("terminate")
os.pullEvent("terminate")
Posted 21 February 2013 - 10:41 AM
You can also use "return" or "shell.exit()".
Posted 21 February 2013 - 11:00 AM
adding on to what sammich lord said, if your program is a while loop you can use "break"
Posted 21 February 2013 - 11:07 AM
Thanks, the os.queueEvent("terminate"), os.pullEvent("terminate") works perfectly for me.
Posted 22 February 2013 - 03:25 PM
Thanks, the os.queueEvent("terminate"), os.pullEvent("terminate") works perfectly for me.
Don't. It's a bad coding habit and prints "Terminated." to the screen. Use error() (empty parentheses) or, if your program is enclosed with a loop, just use break.
Posted 22 February 2013 - 03:47 PM
Its actually not a bad coding habit. Using error() is actually the bad coding habit. Unfortunately 'error' is one of the easiest ways to do it in CC since we don't have functions such as 'os.exit'.Don't. It's a bad coding habit and prints "Terminated." to the screen. Use error() (empty parentheses) or, if your program is enclosed with a loop, just use break.
Posted 22 February 2013 - 04:18 PM
Actually, queuing terminate calls error(). (Look in the bios) so queuing terminate is actually worse than just calling error()Its actually not a bad coding habit. Using error() is actually the bad coding habit. Unfortunately 'error' is one of the easiest ways to do it in CC since we don't have functions such as 'os.exit'.Don't. It's a bad coding habit and prints "Terminated." to the screen. Use error() (empty parentheses) or, if your program is enclosed with a loop, just use break.
Posted 22 February 2013 - 09:12 PM
If you return from outside a function, you return from the whole program - because the whole program is actually a single big function.
Posted 23 February 2013 - 03:05 PM
If you return from outside a function, you return from the whole program - because the whole program is actually a single big function.
Interesting, I never knew that.
Posted 24 February 2013 - 09:54 AM
In theory can't you go do this
Clear()
Term.setCursorPos(1,1)
Clear()
Term.setCursorPos(1,1)
Posted 24 February 2013 - 10:01 AM
Is there a command to exit a program that brings you back to the command line like terminating? Something like shell.exit(), but not stopping the whole computer.
Has you question actually been answered yet? Mm Oh I see you said os.queueEvent("terminate") works but like people said, it's probably not the best way … if it's outside a function, use return, inside a function - use a boolean or whatever for it to check if it must end or whatever
In theory can't you go do this
Clear()
Term.setCursorPos(1,1)
Clear() is not a function
You're probably thinking of term.clear() and all that does is clear the screen