TScript Return Keyword (return)

The return keyword

The "return" keyword operations similar to return statements in C/C++, however in TScript methods can only return an error result to indicate whether or not the execution completed correctly. This keyword ties together with the "if..else" keywords that control the execution flow of the script and allows the programmer to control execution in case of errors, almost identical to the "try..catch" keywords in C++. The basic syntax for the "return" keyword is: -

  • TScript
return error = 1, error = "error text";

With the "return" keyword, statements can be executed before the actual return in performed and are separated by a comer ",". If there are no statements contained in the return statement, then the method will return from this point without returning an error. If there is only one statement in the statement, then TScript will substitute a default value to indicate an error.

The "return" keyword operates with the "if..else" keywords by controlling executing of the script. In the following example, the static method "myMethod" returns an error, witch is caught in the static main method and handled.

  • TScript
static myMethod(Integer parameter){
   if(parameter < 100)
       return error = "This parameter is too small", error = 1;
   ...
   if(okay) return;//explicitly returning without error
   ...
   //implicitly returning without error
}

public static main(variable arguments){
   if(myMethod(arguments.Integer(]]){
      if(error != 1) 
         return error;//can't fix this error, pass it on
   }
   ...
}