- Joined
- Jul 10, 2007
- Messages
- 6,306
JASS:
library Trigger
struct Trigger extends array
private static trigger array triggers
private static integer instanceCount = 0
private static integer array recycle
private static integer recycleCount = 0
public static method create takes nothing returns thistype
if (recycleCount != 0) then
set recycleCount = recycleCount - 1
set triggers[recycle[recycleCount]] = CreateTrigger()
return recycle[recycleCount]
endif
set instanceCount = instanceCount + 1
return instanceCount
endmethod
public method destroy takes nothing returns nothing
if (triggers[this] != null) then
call DestroyTrigger(triggers[this])
set triggers[this] = null
set recycle[recycleCount] = this
set recycleCount = recycleCount + 1
endif
endmethod
public method add takes boolexpr c returns nothing
call TriggerAddCondition(triggers[this], c)
endmethod
public method fire takes nothing returns nothing
call TriggerEvaluate(triggers[this])
endmethod
endstruct
function OnEvent takes boolexpr c, integer eventId returns nothing
call Trigger(eventId).add(c)
endfunction
endlibrary
Why?
JASS:
globals
integer EVENT_UNIT_REMOVE //set on init
integer EVENT_UNIT_DEATH //set on init
endglobals
function test takes nothing returns nothing
call OnEvent(Condition(function myFunc), EVENT_UNIT_REMOVE)
endfunction
Last edited: