- Joined
- Oct 11, 2012
- Messages
- 711
Hi all. The following code has this problem: when I use both unit A and unit B to cast it, instead of displaying both A's and B's names, only the unit's name of the first caster will be displayed. For example, instead of displaying"A,B,A,B,A,B....", it displays "A,A,A,A,A,A,A,....".(The second timer does fire, but with the name "A", not "B"). It seems "this.caster" does not catch the second caster...Why is it? Furthermore, if I use "this.deallocate" in the "callback" method, then only the unit's name of the second caster will be displayed. ... Thanks.
JASS:
struct test
private unit caster
private timer t
private thistype next
private thistype prev
private static method callback takes nothing returns nothing
local thistype this = thistype(0).next
call BJDebugMsg(GetUnitName(this.caster))
//call this.deallocate()
set this = this.next
endmethod
private static method run takes nothing returns boolean
local thistype this = thistype.allocate()
set this.next = 0
set this.prev = thistype(0).prev
set thistype(0).prev.next = this
set thistype(0).prev = this
set this.caster=GetTriggerUnit()
set this.t=CreateTimer()
call TimerStart(this.t,1.00,true, function thistype.callback)
return false
endmethod
private static method onCast takes nothing returns boolean
if GetSpellAbilityId() == 'A003' then
call BJDebugMsg("oncast")
call thistype.run()
endif
return false
endmethod
private static method onInit takes nothing returns nothing
local trigger t
set t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t, Condition(function thistype.onCast))
set t = null
endmethod
endstruct