- Joined
- Jun 23, 2007
- Messages
- 4,066
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.
What do you guys think?
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