Last modified 18 months ago
Last modified on 11/30/10 02:30:43
It is possible to define custom script functions to reuse certain functionality throughout the script.
Functions have the following syntax:
function <return type> <function name> ([<argument type> <argument name>, ... ]) { <code> return ... ; }
Examples:
function void displayVictoryMessage(int winner) { console ("Player " & getPlayerName(winner) & " has won the game"); } function float calculateMinimum (float f1, float f2) { if (f1 < f2) { return f1; } return f2; }
Functions look almost identical to their C counterparts, except that the beginning of a function is marked with the function keyword.
It is possible to declare functions before their first use, so you can use a function before it is defined later in the script:
function void displayVictoryMessage(int winner); function float calculateMinimum (float f1, float f2);
A function is called by providing its name and arguments.
displayVictoryMessage(0); ... console("Minimum of 2 and 2.1 is " & calculateMinimum(2.0, 2.1));
Like in C return <return expression>; or for void functions just return; returns execution to the caller.
{{Scripting manual}} Category:Scripting manual ?
