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

Exiting a program

Started by abihoooo, 21 February 2013 - 09:34 AM
abihoooo #1
Posted 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.
FuuuAInfiniteLoop(F.A.I.L) #2
Posted 21 February 2013 - 10:39 AM

os.queueEvent("terminate")
os.pullEvent("terminate")
Sammich Lord #3
Posted 21 February 2013 - 10:41 AM
You can also use "return" or "shell.exit()".
NDFJay #4
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"
abihoooo #5
Posted 21 February 2013 - 11:07 AM
Thanks, the os.queueEvent("terminate"), os.pullEvent("terminate") works perfectly for me.
Dlcruz129 #6
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.
theoriginalbit #7
Posted 22 February 2013 - 03:47 PM
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.
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'.
1lann #8
Posted 22 February 2013 - 04:18 PM
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.
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'.
Actually, queuing terminate calls error(). (Look in the bios) so queuing terminate is actually worse than just calling error()
immibis #9
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.
Dlcruz129 #10
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.
Lewis.holcombe #11
Posted 24 February 2013 - 09:54 AM
In theory can't you go do this

Clear()
Term.setCursorPos(1,1)
remiX #12
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