• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

*Need opinion* [Snippet] GameStart

Status
Not open for further replies.
For when scripts need to do stuff post-initialization. This allows you to run code when the game starts to prevent users (and other dependencies) from creating/destroying many timers.

JASS:
library GameStart initializer onInit

    globals
        private trigger T=CreateTrigger()
    endglobals
    
    // these two are the same
    function onGameStart takes boolexpr func returns nothing
        call TriggerAddCondition(T, func)
    endfunction
    
    function RegisterGameStartEvent takes boolexpr func returns nothing
        call TriggerAddCondition(T, func)
    endfunction
    
    // run threads and destroy handles
    private function onExpire takes nothing returns nothing
        call TriggerEvaluate(T)
        call DestroyTimer(GetExpiredTimer())
        call DestroyTrigger(T)
        set T=null
    endfunction
    
    private function onInit takes nothing returns nothing
        call TimerStart(CreateTimer(), 0, false, function onExpire)
    endfunction
    
endlibrary
JASS:
function display takes nothing returns boolean
    call BJDebugMsg("Game started.")
    return false
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_008 takes nothing returns nothing
    call onGameStart(Filter(function display))
endfunction
What do you guys think?
 
Status
Not open for further replies.
Top