• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

*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