Killing a lua script

Forums: Killing a lua script
Forum for OctaneRender Lua scripting examples, discussion and support.

Killing a lua script

Postby MB » Fri Jun 02, 2017 4:28 pm

MB Fri Jun 02, 2017 4:28 pm
All,

What is the best way to exit a running script,

os.exit()

This line crashes octane.

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

thx
Windows 11, 2x Intel I9, 64GB Ram, 2x GTX 1080 TI, 1 x RTX 380 TI, Oculus Quest 2
User avatar
MB
Licensed Customer
Licensed Customer
 
Posts: 168
Joined: Tue Jan 15, 2013 3:41 am
Location: Washington, D.C.

Re: Killing a lua script

Postby bepeg4d » Sat Jun 03, 2017 6:43 am

bepeg4d Sat Jun 03, 2017 6:43 am
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)
octane.gui.showDialog{
type = octane.gui.dialogType.BUTTON_DIALOG,
title = "Error",
text = text }
end

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

hope it helps,
ciao beppe
User avatar
bepeg4d
Octane Guru
Octane Guru
 
Posts: 9940
Joined: Wed Jun 02, 2010 6:02 am
Location: Italy

Re: Killing a lua script

Postby MB » Mon Jun 05, 2017 4:15 pm

MB Mon Jun 05, 2017 4:15 pm
Beppe

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.

best
Windows 11, 2x Intel I9, 64GB Ram, 2x GTX 1080 TI, 1 x RTX 380 TI, Oculus Quest 2
User avatar
MB
Licensed Customer
Licensed Customer
 
Posts: 168
Joined: Tue Jan 15, 2013 3:41 am
Location: Washington, D.C.

Re: Killing a lua script

Postby roeland » Tue Jun 06, 2017 10:34 pm

roeland Tue Jun 06, 2017 10:34 pm
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.

--
Roeland
User avatar
roeland
OctaneRender Team
OctaneRender Team
 
Posts: 1808
Joined: Wed Mar 09, 2011 10:09 pm

Return to Lua Scripting


Who is online

Users browsing this forum: No registered users and 7 guests

Thu Mar 28, 2024 11:45 pm [ UTC ]