Page 1 of 1

Killing a lua script

PostPosted: Fri Jun 02, 2017 4:28 pm
by MB

What is the best way to exit a running script,


This line crashes octane.

I would like to do some error checking and end the whole thing if one is encountered.


Re: Killing a lua script

PostPosted: Sat Jun 03, 2017 6:43 am
by bepeg4d
Hi MB,
I'm not a programmer, but an architect, but my solution to error handling is to use an if state with return:
local function showError(text)
type = octane.gui.dialogType.BUTTON_DIALOG,
title = "Error",
text = text }

if x == 0 then
showError("Your error message")

hope it helps,
ciao beppe

Re: Killing a lua script

PostPosted: Mon Jun 05, 2017 4:15 pm
by MB

Thanks for responding. I will try tomorrow when I'm back in the office, but if memory serves me correctly that will not exit the program completely.


Re: Killing a lua script

PostPosted: Tue Jun 06, 2017 10:34 pm
by roeland
To be a bit more technical, a Lua script is treated the same as a function body. So you can use return to exit your script. If you're writing a script you want to call from the command-line you may return an integer number, which will then be visible as the exit code of the octane process.

You can also call the error function: error("oops") to raise an error. The effect depends on the context:
  • Raising an error in the main script (or in any function called directly from there) will stop the script. When called from the command line, this results in a non-zero exit code.
  • Raising an error in a render callback will stop the render.
  • GUI callbacks should not raise errors, you'll have to add some handling yourself to close any open dialogs.

os.exit() will exit the application, but I recommend not using this function as it can interfere with the authentication management. For batch processes, use the --stop-after-script or --no-gui option instead to exit octane after the script finishes.