Difference between revisions of "User Defined Function"

Jump to navigation Jump to search
295 bytes added ,  00:18, 28 May 2014
tweaked
imported>Odessa
(stub overview)
 
imported>Odessa
(tweaked)
Line 1: Line 1:
User defined functions (UDF) are added by NVSE V4. They must be saved as 'object' type scripts that must use the "Function" block type only. Although 'object' type, they must not be attached to any object and are instead called directly by script name from within other scripts, using the [[Call]] command.  
User defined functions (UDF) are added by NVSE V4. They must be saved as 'object' type scripts that must use the "Function" block type only. Although 'object' type, they must not be attached to any object and are instead called directly by script name from within other scripts, using the [[Call]] command.  


UDFs may optionally return a single value of any type, using the [[SetFunctionValue]] command within them. They may optionally accept one or more arguments of any type, which are specified within curly braces:
UDFs may optionally return a single value of any type, using the [[SetFunctionValue]] command within them. They may optionally accept one or more arguments of any type, which are defined within curly braces:
<pre>
<pre>
Begin Function { arg1, arg2..}
int arg1 ; * args are optional
ref arg2
float arg3 ....
 
Begin Function { arg1, arg2, arg3... }
     ; * body
     ; * body
End  
End  
</pre>
and called in a similar way to regular functions:
<pre>
Call SomeUDF arg1, arg2, arg3...
let SomeVariable := Call SomeOtherUDF arg1
if eval (call SomeSuitableUDF)
    ; the UDF return evaluates to true
endif
</pre>
</pre>


Line 15: Line 29:
; ***
; ***


; * vars
; * local vars
array_var aNew
array_var aNew
int iKey
int iKey
Line 45: Line 59:
array_var aBeatles
array_var aBeatles


Begin GameMode ; * some block type
Begin GameMode ; * or some other block type


     let aBeatles := Ar_List JohnREF, PaulREF, GeorgeREF, RingoREF
     let aBeatles := Ar_List JohnREF, PaulREF, GeorgeREF, RingoREF
Anonymous user

Navigation menu