• 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.

*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