• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Function callbacks

Status
Not open for further replies.

LeP

LeP

Level 13
Joined
Feb 13, 2008
Messages
543
What is the best and most efficient way to do function callbacks?
This is my situation:
I'm using a timer with a 0 timeout to callback a function, but unfortunately,
I can't use boolexprs (which I'm using instead of code due to the lack of code arrays).

Not that you gave much information, but use function interfaces.
 
Actually, I just decided to create an Execute Function library :)
It uses dynamic triggers (That way, it could support boolexpr and code varaibles :))

edit
Check this out:
JASS:
library ExecuteFunction
    function ExecuteBoolexpr takes boolexpr b returns nothing
        local trigger t = CreateTrigger()
        call TriggerAddCondition(t,b)
        call TriggerEvaluate(t)
        call DestroyTrigger(t)
        set t = null
    endfunction
    
    function ExecuteCode takes code c returns nothing
        local trigger t = CreateTrigger()
        call TriggerAddCondition(t,Condition(c))
        call TriggerEvaluate(t)
        call DestroyTrigger(t)
        set t = null
    endfunction
endlibrary
 
Level 14
Joined
Nov 18, 2007
Messages
816
Okay. Since you apparently didnt read what lep posted, i guess ill have to list all the reasons you shouldnt be using that snippet.

  • What you call executing should actually be called evaluating
  • Youre dynamically creating and destroying triggers, the overhead of which makes this solution terribly slow
  • Youre entirely missing the ability to pass arguments to the invoked function and return what the invoked function returned (only works when evaluating code)
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
Sure, but at least you don't have to handle the trigger creation yourself, and it will be done only one time during map init.
Also you can use functions arguments and choice to returns something (in the background it will use global variables).

vJass is more friendly to use.
 
I know that snippet is slow, but it's an alternative for ExecuteFunc .. especially when you can't get the name of the function. (Or so I've heard)
It's alright for now.

Just one question:
Assume I have a boolexpr variable called func
If I input func.name, would it return the name of the boolexpr? Or would it just return something like SCOPE_PREFIX+func?
 
Level 14
Joined
Nov 18, 2007
Messages
816
You dont seem to get it... Dont use the snippet you wrote.
Use SomeFunction.evaluate(<Params>) or SomeFunction.exeucte(<Params>)

Or declare a function interface and an array of it and then execute whichever index of this array that you like.
 
Last edited by a moderator:
I'm not going to use the snippet.
If you read the last few sentences in the section above function interfaces in the Manual, you'd know what I'm talking about when I say:
Assume I have a boolexpr variable called func
If I input func.name, would it return the name of the boolexpr? Or would it just return something like SCOPE_PREFIX+func?

Anyway, close this thread.
Problem Solved.
 
Last edited by a moderator:
Status
Not open for further replies.
Top