functionName( argumentList )
Functions are global and may not be nested.
C/C++ users: There is no need to declare a function before calling it, however the function must exist or the compilation of the function will fail. The following is perfectly legal:
return( NotDeclaredYet() );
return( 5 );
C/C++ users: All arguments are pass-by-value, there is currently no way to pass-by-reference.
The returnValue is a value that is "returned" to the caller after the function has finished executing. If a variable in Command contained an expression with a single function call, then the variable would take on the return value of the function after it had executed. For example if the variable Exp_1 had the expression MoveTo(Null_1, Null_2, 1); if the operation was successful then Exp_1 would have a value of 1. We use the 'return' function to return a value from a script.
C/C++ users: 'return' is a function in messiah:script, not a keyword. Therefore you must enclose the return value in parentheses, it is not optional.
The functionName is how we identify the function to messiah, this is the name that will be used to call the function from an expression, the command line, or even another script/function. This brings up the topic of "namespaces". There will be a more formal discussion on namespaces later, for now just know that you can have a function in one script that has the same name as another function in a separate script. When you call these functions you need to qualify which one you are referring to by preceding the function name with the name of the script file that contains it. For example if you had a function called "bar" and it was contained in the file "foo.msa", then you would call the function like so: foo.bar().
The argumentList are the values you pass to the function when you call it. By passing different values the function's behavior can be altered. For example, using our old friend MoveTo(), the functions MoveTo(Null_1, Null_2, 1) and MoveTo(Null_3, Null_2, 1) differ in the item that is going to get moved thereby making the MoveTo() function more general (i.e. it's not coded to operate on a specific item(s) rather the items that it operates on are supplied by the caller).
The functionBody is where we put the statements and control structures that define the operations that the function performs.
|Converted from CHM to HTML with chm2web Pro 2.82 (unicode)|