Functions and the return statement

Functions combine several statements under one name. You can execute the entire set by calling it and passing to it any information it needs. You pass information to a function by enclosing the information in parentheses after the name of the function. Pieces of information that are passed to a function are called parameters. The parameters are optional.

A function can contain zero or more return statements. You can use the return statement to return a result value from the function back to its caller.

You can also use the return statement in the main block of the script file. In that case the execution of the whole script is terminated.


var Number1 = 10;
var Number2 = 20;
Game.Msg("Result is: " + MyFunction(Number1, Number2));
function MyFunction(Param1, Param2)
   var Result;
   Result = Param1 * Param2;
   return Result;