HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

calling a function vs ExecuteFunc

06-26-2007, 06:04 AM#1
zen87
Collapse JASS:
function A takes integer a, integer b returns nothing
//do something
endfunction

function TestTrig takes nothing returns nothing
    call A(123,321)
//...

Collapse JASS:
globals
    private integer Temp_a
    private integer Temp_b
endglobals

function B takes nothing returns nothing
 local integer a = Temp_a
 local integer b = Temp_b
//do something
endfunction

function TestTrig takes nothing returns nothing
    set Temp_a = 123
    set Temp_b = 312
    call ExecuteFunc("B")
//...

basically both does almost the same thing, just that the ExecuteFunc doesn't have troubles such as where the function B is placed above or bottom of function Test Trig, my question is : is it encouraged to mass spam ExecuteFunc ? Will it cause any problems or slower perfomance compared to calling a function instead ?

thx
06-26-2007, 06:26 AM#2
Captain Griffen
ExecuteFunc is far slower, as it has to create a new thread. Very much slower in fact.
06-26-2007, 07:11 AM#3
DioD
execute far more flexeble in use.

you may generate complex set of function calls and call random actions from string array and execute.
06-26-2007, 08:49 AM#4
Toadcop
TriggerEvaluate() is faster but the usage is more problematic =\ to get back and forward "conection" you would need a boolexpr variable (array). but it almost 2x faster than Execute (TriggerExecute is also slow)

// PS Vex could include some stuff (vJass) to make it easier for example.
Code:
call CusExec("My_Func")
if it would use only static strings not variables, so it could search for function with this name and generate a trigger with condition and replace this code !
to
Code:
call TriggerEvaluate(gen_exec_My_Func_trig)
so theoreticaly it's possible =) but ExecuteFunc() rules cause you got not much trouble with it.
06-26-2007, 02:37 PM#5
Vexorian
call My_Func.execute()
06-26-2007, 03:36 PM#6
zen87
O_o when did u add that to vJass... aw... need to go read up the latest vJass manual now...
06-26-2007, 03:51 PM#7
SFilip
ExecuteFunc is only encouraged when you are in need of running in a new thread.
And when is this?
Usually when you hit the thread limit (when you know your trigger will run 5000 functions or so). Or possibly when messing with TriggerSleepAction - this function actually pauses the whole thread so take a look at this code:
Collapse JASS:
function bar takes nothing returns nothing
    call TriggerSleepAction(5)
    call BJDebugMsg("!")
endfunction

function foo takes nothing returns nothing
    call TriggerSleepAction(5)
    call bar()
    call BJDebugMsg("!")
endfunction
It waits 10 seconds overall (5 in foo and 5 in bar right after that) and then displays an exclamation mark twice.
Now if you change call bar() into call ExecuteFunc("bar") the whole thing changes...
It waits 5 seconds, displays one exclamation mark, waits another 5 seconds and then the second exclamation appears.
Simply put, running in a new thread means that the executed function is completely independent. But, as stated above, it's also slower so use only if you have to.

Also worth mentioning that if you give ExecuteFunc an invalid name or some function that takes/returns something, the game crashes.
06-26-2007, 04:01 PM#8
zen87
I know about that, I'm asking about perfomance and stability of ExecuteFunc here. Anyway I seldom use TriggerSleepAction now days lol.

as DioD said, I'm trying to do something like that, so I was wondering will it cause any trouble if I were to mass it...
06-26-2007, 04:18 PM#9
DioD
it wont cause fps drop more then 3
06-26-2007, 04:21 PM#10
Vexorian
Quote:
Originally Posted by SFilip
ExecuteFunc is only encouraged when you are in need of running in a new thread.
And when is this?
Usually when you hit the thread limit (when you know your trigger will run 5000 functions or so). Or possibly when messing with TriggerSleepAction - this function actually pauses the whole thread so take a look at this code:
Collapse JASS:
function bar takes nothing returns nothing
    call TriggerSleepAction(5)
    call BJDebugMsg("!")
endfunction

function foo takes nothing returns nothing
    call TriggerSleepAction(5)
    call bar()
    call BJDebugMsg("!")
endfunction
It waits 10 seconds overall (5 in foo and 5 in bar right after that) and then displays an exclamation mark twice.
Now if you change call bar() into call ExecuteFunc("bar") the whole thing changes...
It waits 5 seconds, displays one exclamation mark, waits another 5 seconds and then the second exclamation appears.
Simply put, running in a new thread means that the executed function is completely independent. But, as stated above, it's also slower so use only if you have to.

Also worth mentioning that if you give ExecuteFunc an invalid name or some function that takes/returns something, the game crashes.
I now just use .execute in those cases
06-26-2007, 05:34 PM#11
Toadcop
Quote:
call My_Func.execute()
why does it copy the code O_O (function) ? for some compability ?
i don't know... what is to do... create trigger + add codition (give a function a id) replace all call with triggereavaluate(trigg[function id]) thats all yes intialization of this triggers can me below config =) but to copy the function !?