Functions as objects
For vJass functions may behave as objects with 2 methods: evaluate
and execute
, both methods got the same arguments list as the function, and evaluate got its return value as well.
Using functions as objects has a couple of advantages, evaluate()
allows you to call the function even from code that is above its function declaration, execute allows the same but it is also able to run the function in another thread.
The disadvantages are: Functions that are used with evaluate()
, should not use GetTriggeringTrigger()
(but you may use any other event response) or any sync native, evaluate()
does not support waits, and evaluate() is slower than a normal function call.
.execute()
is actually faster than good old ExecuteFunc
, and in later versions it might actually get even faster. evaluate halves the duration of ExecuteFunc and it may get much better later.
For functions that have function arguments you would have to use global variables to pass arguments when using ExecuteFunc
, .execute
and .evaluate
will pass the arguments directly.
These are mutually recursive functions, and with normal Jass this would give a syntax error, in order to prevent this issue you may use evaluate:
Let us say you need to destroy an special effect after waiting x seconds using a wait. You could use a timer but for example sake we are going to use a normal wait, we do not want to stop execution of the function calling this effect destroying function so we need a new thread:
The .name
member in functions will return a string containing the function's compiled name, useful when you want to use a scope function in things like ExecuteFunc
.