variable gets nulled within a timer

Status
Not open for further replies.
Level 3
Joined
Mar 10, 2018
Messages
32
I want to give a hero bonus speed and agility for some time via triggers. However after some time my variables turn null for no apparent reason, which makes me unable to subtract them back.
Lua:
function spell()
    local trig = CreateTrigger()
    TriggerRegisterAnyUnitEventBJ(trig, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    TriggerAddAction(trig, function()
        if GetSpellAbilityId() ~= FourCC('A000') then return end
        local u = GetTriggerUnit()
       
        SetUnitAnimation(u, 'death')
        PauseUnit(u, true)
       
        local tix = 0
        TimerStart(CreateTimer(), 0.1, true, function (  ) 
            if tix == 35 then 
                PauseUnit(u, false)                   
                print('start')
                SetUnitVertexColor(u, 50, 20, 20, 100)
                SetUnitAnimation(u, 'stand ready')

                local sp = 522 - BlzGetUnitRealField(u, UNIT_RF_SPEED)
                BlzSetUnitRealField(u, UNIT_RF_SPEED, sp + BlzGetUnitRealField(u, UNIT_RF_SPEED))
                print(sp)
       
                local ag = BlzGetUnitIntegerField(u, UNIT_IF_AGILITY)
                BlzSetUnitIntegerField(u, UNIT_IF_AGILITY, ag + 15)
                print(ag)
            elseif tix == 60 then 
                SetUnitVertexColor(u, 255, 255, 255, 255)

                print(sp)
                --BlzSetUnitRealField(u, UNIT_RF_SPEED, BlzGetUnitRealField(u, UNIT_RF_SPEED)-sp)

                print(ag)
                --BlzSetUnitIntegerField(u, UNIT_IF_AGILITY, ag)
       
                PauseTimer(GetExpiredTimer())
                DestroyTimer(GetExpiredTimer())
                print('end')
            end
           
            tix = tix + 1
           
        end)
    end)
end
upload_2020-11-30_16-50-53.png


p.s. is there a way to add and subtract green stats with triggers or I have to use passive item abilities for this purpose?
p.p.s. does this leak?
 
Status
Not open for further replies.
Top