Is there a command in Maxscript that allows you to stop a script early? Say for example the script relies on having a single object as a selection. If there’s nothing to select then it won’t work.
myObj = $
if ($ == undefined) then STOP
-- rest of code
where STOP represents is the elusive or fictional stop command
Rather than having to do a test like:
myObj = $
if ($ != undefined) then
(
--rest of code
)
Which is fine, but it does mean to put the majority of the script in brackets – which I find it makes the code a but uglier to edit.
It depends, you can usually use
returnto force an early exit. This will work even in case of event handlers as they are basically just functions:Due to some implementation details, if used in a body of a loop or somewhere else where it might be executed multiple times, it would make the whole script slower, though.
If you only want to exit the script and only print information in the listener,
throwmight be a better function to use.However in most cases what you are currently using is the most fitting solution. If you want to improve it (especially if you find yourself writing the same piece of code over and over again), you can write a custom struct similar to, for example,
Filters: