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

Function for quit program

Started by Drifter, 11 April 2013 - 07:32 AM
Drifter #1
Posted 11 April 2013 - 09:32 AM
Hi, is there any function for exit/quit current running program? I found os.reboot(), but this function reset PC,
I'm looking for something like os.close() (this function doesn't exists, so don't search for that) . I tried shell.exit(), but it doesn't work.

And yes I know I can do it other way, but I want to know if something like this exists. Thnx
Sammich Lord #2
Posted 11 April 2013 - 09:34 AM
You can write "return" and it will exit the current function(Which the script is called as a function).
Spongy141 #3
Posted 11 April 2013 - 12:54 PM
Yeah its kinda weird, I was researching about why you can't do

os.exit()
in CC, I still didn't find a reason, but like Sammich Lord said, "return" always works too.
Engineer #4
Posted 11 April 2013 - 01:45 PM
If you really need to, you can use error()
You would use this in a function, for example.

error('something terrible happened:/')
-- or just
error()
Spongy141 #5
Posted 11 April 2013 - 02:14 PM
If you really need to, you can use error()
You would use this in a function, for example.

error('something terrible happened:/')
-- or just
error()
Isn't it

printError("Something terrible happened :/")
not what you said. Nvm after testing it, either works, but doing my say will give you more freedom to make a custom error. But still doing "error()" would still exit the program.
Smiley43210 #6
Posted 12 April 2013 - 01:14 AM
Yea, and if you look in the bios.lua, thats how Ctrl + T works. Just conjures up an error(). But I think if you provide a message, it will display the program name and the line number the error was called from. So instead, if you want a message, you might be better off just print() ing a message and then error() ing the script.
PixelToast #7
Posted 12 April 2013 - 08:04 AM
Yea, and if you look in the bios.lua, thats how Ctrl + T works. Just conjures up an error().
well, when you hold ctrl-t it triggers the "terminate" event wich bypasses the event filter in the parallel api and goes to the program's coroutine and the os.pullEvent it called triggers an error and is catched by the nearest pcall wich will most likely be in the shell