How to terminate script execution from within DazScript?

shoei321shoei321 Posts: 63

Simple question - I need to be able to terminate execution of my script under certain conditions, for example :

if (unrecoverableErrorCondition) {

But I exit() doesn't do it, nor does System.exit(), return, or any of the usual candidates. I don't see anything under DzScriptContext or DzSystem for this either. How is this best done?



  • Richard HaseltineRichard Haseltine Posts: 21,491
    edited December 1969

    I don't know. continue would terminate any loop you were in, then you could have some kind of check to make sure execution of instructions ended -

    for ( var n = 0 ; n < limit && ! GiveUp ; n++ ) {      if (unrecoverableErrorCondition) {       GiveUp = true;       continue;     }  }

  • shoei321shoei321 Posts: 63
    edited December 1969

    continue and break just skip or exit the current looping structure. I'm looking to end script execution all together.

    In Java this would be System.exit(), in PHP and Perl exit(), in Python sys.exit(), etc. I can't seem to find the equivalent in DazScript, nor does it seem to be in the ECMAScript spec.

  • Richard HaseltineRichard Haseltine Posts: 21,491
    edited December 1969

    I was suggesting using continue to get out of the loop you are in, if any, and then using a boolean flag to make sure that nothing else is done - so the script should then just run do-nothing function calls until it gets to its end. Or put error checks around the actual code - I often end up with so many nested if ( we-have-the-thing-we-need) statements that in a print the actual working code would be on the right margin.

  • rbtwhizrbtwhiz Posts: 654
    edited November 2012

    Wrap your code in a function and exit the function early...

    function myFunction( bExitEarly )
     if( bExitEarly ){
      print( "Exited the function early." );
     print( "Exited at the end of the function." );
    myFunction( true );


    Post edited by rbtwhiz on
Sign In or Register to comment.
Rocket Fuel