- Joined
- Nov 30, 2007
- Messages
- 1,202
I've made this simple event handler for damage detection and deaths in a spell of mine but... There is a theoretical scenario where the units alive in .gr never become 0 and therefore refresh would never happen, so how do I fix my refresh method so that alive (?) units are re-included into addUnit, and what do I have to keep in mind?
I'm not sure the above concept even works, oh unitevent and code cant be a array. What about saving them inside a hash or something and loading them that way? Right... I can't save those two in a hash, only the trigger... Forget about this.
JASS:
struct EventHandler
group gr = CreateGroup()
trigger trg = null
code func
unitevent uEvent
boolean active = false
static method addUnit takes unit u returns nothing
if not active then
call .refresh()
set .active = true
endif
if not IsUnitInGroup(u, .gr) then
call GroupAddUnit(.gr, u)
call TriggerRegisterUnitEvent(.trg, u, .uEvent)
endif
endmethod
static method refresh takes nothing returns nothing
if .trg != null then
call DestroyTrigger(.trg)
endif
set .trg = CreateTrigger()
call TriggerAddCondition(.trg, Condition(.func))
call GroupClear(.gr)
endmethod
static method create takes unitevent ue, code c returns EventHandler
local thistype tmp = .allocate()
set .uEvent = ue
set .func = c
return tmp
endmethod
endstruct
I'm not sure the above concept even works, oh unitevent and code cant be a array. What about saving them inside a hash or something and loading them that way? Right... I can't save those two in a hash, only the trigger... Forget about this.
Last edited: