#Return true only after C_Timer.After is finished

5 messages · Page 1 of 1 (latest)

edgy nebula
#

Hi, I have made a code that makes a counter, but it is required that the counter is executed only after C_Timer.After is finished. As far as I understand C_Timer.After is executed asynchronously, so return true happens immediately when the subevent is executed. How can this problem be solved?

function(allstates, e, ...)
    if e == "COMBAT_LOG_EVENT_UNFILTERED" then
        local timestamp, subevent, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags, spellID = ...
        
        if sourceGUID == aura_env.myGUID then
            if (subevent == "SPELL_CAST_SUCCESS" and spellID == 1943) then

                C_Timer.After(1, function() 
                        aura_env.chance = aura_env.chance + 1
                        
                        allstates[""] = {
                            show = true,
                            changed = true,
                            autoHide = true,
                            stacks = aura_env.chance,
                        }
                end)
                
                return true
                
            elseif ((subevent == "SPELL_AURA_APPLIED" or subevent == "SPELL_AURA_REFRESH") and spellID == 424493) then
                
                aura_env.chance = 0
                
                allstates[""] = {
                    show = true,
                    changed = true,
                    autoHide = true,
                    stacks = aura_env.chance,
                }
                
                return true
            end
        end
    end
end
hushed hazel
# edgy nebula Hi, I have made a code that makes a counter, but it is required that the counter...
function(allstates, e, ...)
    if e == "COMBAT_LOG_EVENT_UNFILTERED" then
        local timestamp, subevent, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags, spellID = ...
        if sourceGUID == aura_env.myGUID then
            if (subevent == "SPELL_CAST_SUCCESS" and spellID == 1943) then
                C_Timer.After(1, function()
                        WeakAuras.ScanEvents("INCREASE_CHANCE", aura_env.id)
                end)
            elseif ((subevent == "SPELL_AURA_APPLIED" or subevent == "SPELL_AURA_REFRESH") and spellID == 424493) then
                allstates[""] = {
                    show = true,
                    changed = true,
                    stacks = 0,
                }
                return true
            end
        end
    elseif e == "INCREASE_CHANCE" and ... == aura_env.id then
        local state = allstates[""]
        if state then
            state.stacks = state.stacks + 1
            state.changed = true
            return true
        end
    end
end
#

don't forget to add INCREASE_CHANCE to list of events

#
INCREASE_CHANCE CLEU:SPELL_CAST_SUCCESS:SPELL_AURA_APPLIED:SPELL_AURA_REFRESH
edgy nebula