Difference between revisions of "User Functions"

Jump to navigation Jump to search
959 bytes added ,  16:32, 20 March 2011
Added some notes
imported>QQuix
(Added link to the list of user functions (Category page))
imported>QQuix
(Added some notes)
Line 1: Line 1:
__NOTOC__
User-Defined Functions - a feature added with OBSE v18
User-Defined Functions - a feature added with OBSE v18


Line 31: Line 32:
A function script can contain only one block. The name of the script is the name of the function.  
A function script can contain only one block. The name of the script is the name of the function.  


Function scripts should never be attached to any object.  
Parameters are stored in local variables and must be indicated within {braces} in the function definition.  


And all variables in a function script must be declared before the function body.
A set of empty braces indicates the function takes no arguments.
 
When parsing a function call, the compiler will verify that the number and type of the arguments match those expected by the function's parameter list.
 
If the called function is specified as a ref variable this validation cannot be performed; it is the scripter's responsibility to ensure the argument list is valid to avoid errors at run-time.
 
===Notes===


*Function scripts should never be attached to any object.


Parameters are stored in local variables and must be indicated within {braces} in the function definition;
*All variables in a function script must be declared before the function body.


A set of empty braces indicates the function takes no arguments.  
*Local variables and argument variables retain their values only until the function returns.
 
*Numbers, references and strings passed as parameters are copied to their proper local variables. Changing these copies do not change the original variables in the calling script.


Local variables and argument variables retain their values only until the function returns.
*Arrays, on the other hand, are passed as pointers to the original arrays, therefore changes to arrays passed as parameters will persist after the user function returns.


*Clean up
**Strings passed as parameters are destroyed when the function returns.
**Any other string stored in local variables must be explicitly destroyed with [[sv_Destruct]] before the function execution ends (or else they will bloat the savegame).
**Arrays passed as parameters are pointers to the original arrays, so no clean up is necessary (the pointer, itself, is destroyed automatically).
**Local arrays are destroyed automatically when the function execution ends.
**All other local variables (shorts, floats, refs etc.) are also destroyed when the function execution ends.


When parsing a function call, the compiler will verify that the number and type of the arguments match those expected by the function's parameter list.


If the called function is specified as a ref variable this validation cannot be performed; it is the scripter's responsibility to ensure the argument list is valid to avoid errors at run-time.


Functions have some useful properties.  
Functions have some useful properties.  
Anonymous user

Navigation menu