Notifications
Clear all

[Closed] Is there a way to stop script

Is there a way to stop script if something went wrong
for example:

myObj = $
if ($ == undefined) then EXIT

rest of code

i tried, but get
Exit: not inside a loop

5 Replies
myObj = selection[1]
if isValidNode myObj then
(
-- code here
)
else
(
messagebox "Error"
)

I gave a bad example
i need the script to stop on every first error
and didn’t execute the rest of the code

new example^

if selection.count!=0 then (bla-bla-bla)
else (messagebox "Error"  and exit without continuing execution the script)

if isKindOf i helper!=undefined then (delete Helpers)
else (messagebox "Error"  and exit without continuing execution the script)

backgroundColor=color 255 255 255;
environmentMap=undefined;
lot of code
lot of code
lot of code
lot of code
lot of code
lot of code
rollout blablabla
lot of code
lot of code
(
	if selection.count != 0 then
	(
		if isKindOf selection[1] helper != undefined then 
		(
			delete Helpers
			
			backgroundColor=color 255 255 255;
			environmentMap=undefined;
			--lot of code
			--lot of code
			--lot of code
			--lot of code
			--lot of code
			--lot of code
			rollout blablabla
			--lot of code
			--lot of code
		
		)
		else 
		(
			messagebox "Error"  --and exit without continuing execution the script
		)
		
	)
	else
	(
		messagebox "Error" -- and exit without continuing execution the script
	)


)

Or like this:

(
	continueScriptExecution = true
	if selection.count != 0 then
	(
		bla-bla-bla
	)
	else
	(
		continueScriptExecution = false
		messagebox "Error 1" title:""
	)
	
	if continueScriptExecution then
	(
		if isKindOf i helper!=undefined then 
		(
			delete Helpers
		)
		else 
		(
			continueScriptExecution = false
			messagebox "Error 2"  
		)
	)
	
	if continueScriptExecution then
	(
		backgroundColor=color 255 255 255;
		environmentMap=undefined;
		lot of code
		lot of code
		lot of code
		lot of code
		lot of code
		lot of code
		rollout blablabla
		lot of code
		lot of code
	)
)

how do you use this code? if it’s a handler or a function you can use return()

else
	(
		continueScriptExecution = false
		messagebox "Error 1" title:""
	)

it would be great, but it doesn’t work