• 💀 Happy Halloween! 💀 It's time to vote for the best terrain! Check out the entries to Hive's HD Terrain Contest #2 - Vampire Folklore.❗️Poll closes on November 14, 2023. 🔗Click here to cast your vote!
  • 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 HD Level Design Contest #1 is OPEN! Contestants must create a maze with at least one entry point, and at least one exit point. The map should be made in HD mode, and should not be openable in SD. Only custom models from Hive's HD model and texture sections are allowed. The only exceptions are DNC models and omnilights. This is mainly a visual and design oriented contest, not technical. The UI and video walkthrough rules are there to give everyone an equal shot at victory by standardizing how viewers see the terrain. 🔗Click here to enter!

Function callbacks

Status
Not open for further replies.

LeP

LeP

Level 12
Joined
Feb 13, 2008
Messages
532
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