WeakAuras

Custom Duration Issue (progress bar)

  • 4 posts
    #1 May 30, 2011 at 04:45 UTC - 0 likes

    First, thank you for creating this incredibly useful addon.

    I'm creating a group of two displays to monitor my mage's polymorph. Since I don't want it to rely on having the poly target in focus, I'm using custom combat log triggers for the progress bar.

    Trigger:

    function(_, _, message, _, _, source, _, destGUID, dest, _, _, spellName)
        if (message == "SPELL_AURA_APPLIED" and UnitIsUnit(source or "", "player") and spellName and spellName:find("Polymorph")) then
            WeakAuras_Polymorph_Mob_Name = dest
            WeakAuras_Polymorph_Start = GetTime()
            return true
        end
        if (message == "SPELL_AURA_REFRESH" and UnitIsUnit(source or "", "player") and spellName and spellName:find("Polymorph")) then
            WeakAuras_Polymorph_Start = GetTime()
        end
        return false
    end
    

    Untrigger:

    function(_, _, message, _, _, source, _, destGUID, dest, _, _, spellName)
        if (message == "SPELL_AURA_REMOVED" and UnitIsUnit(source or "", "player") and spellName and spellName:find("Polymorph")) then
            WeakAuras_Polymorph_Mob_Name = nil
            WeakAuras_Polymorph_Start = nil
            return true
        end
        return false
    end
    

    Duration:

    function()
        return (WeakAuras_Polymorph_Start + 50 - GetTime()), 50, function () return (WeakAuras_Polymorph_Start + 50 - GetTime()), 50 end
    end
    

    Name:

    function()
        return WeakAuras_Polymorph_Mob_Name
    end
    

    The progress bar appears and disappears as expected, and the name is always correct. However, the duration behaves very oddly. Most of the time, it functions essentially correctly (counts down from 50 and resets to 50 on refresh). The duration text is using way too many significant digits, but it's functioning. But, occasionally when I sheep a mob, the bar appears with the duration stuck on 50, and no number of refreshes on the same mob will make it countdown again (casting on a new mob typically gets it to count again).

    My initial thought was that the WeakAuras_Polymorph_Start variable was somehow getting set to nil, but that doesn't seem to be the case, because I have a texture display that uses that variable to appear when WeakAuras_Polymorph_Start isn't nil and GetTime() - WeakAuras_Polymorph_Start > 45, which seems to always work, even if the progress bar is bugging out.

    Any ideas? Why does the text of the progress bar duration display all the decimal places when it does work? Is there a much better way to accomplish this?

    Export:

    dq0rmaG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EpC6kOeabLRq(vBkwqHqcGJu4ytsC1bYM00)PwAPLexnPj8E4utqjve(iDbhNsckaHnrw9YxQWeu(mxX8uPLd8LkmwhOjLSmih1LzfixH8lSGLqkOkdbS6ieMOnOEegclPOnO3Bsf00S9eWXfxCbNNrBqZMJr4ZxXI2GMMTNaoOEzt6rim60V)WHdhs4nuhuLQl5mtzb5kKFHfSesG0tXUHkdWWgRRLaU0PF4JHqvQUKZmLfKRq(fwWsibspf7goeco0Pg9dpsLz)HdhoC4WHdz1LzMHEkzBT)WHdhwgG9hoC4qwDzMz4XY1(LbiUGYkFect7Bsf0R69YSkO8lxga)eavqjdriguv6rim2OnO2tXUOnOwr2aeu(mxX8uPLdKbaegRdqvQUKZmL1bUciSyKZmL1VcGq5avKnawh0gFT8QDHpFbfqaAfzdqOT4IlOx17LzvqPjLSS1bY2Kk9a9ty6wVbTx)98S1fo(qdKs048PeTCPrcKsC90v49WPRGEmcF(kw0g07nPcAA2Ec4GMMTNag8EtQGAp1LTbnnBpbCq9YM0Jqy0PF)HdhoKWBOoOkvxYzMYcYvi)clyjKaPNIDdvgGHnwxlbCPt)WhdHQuDjNzklixH8lSGLqcKEk2nCieCOtn6hEKkZ(dhoC4WHdhYQlZmdpwU2F4WHdldW(dhoCiRUmZm0tjBR9ldW(7V)(7V)(7V)(7VFqZ2cmBiUqBbnLuL2nO5ea1vbnBQEuMlOQ8jcAA2Ecyqseavqpc4ciUGsaeuUc5xOumtqF93ZZwx44dnAbzFxoH0zFiB6PMNDKeEpC2jU4cApco9DkrsCra
    
    #2 May 30, 2011 at 18:44 UTC - 1 like

    Well, there's one major problem I can see immediately. The reason your duration text is showing up weirdly is because you're trying to do too much work yourself instead of letting the Progress Bar use its own formatting and updating. Duration info is passed using four arguments, like this:

    return duration, expirationTime, static, inverse
    

    The behavior of a display's duration will vary widely based on the values of these arguments. Most importantly, arguments 1 and 2 have a slightly different meaning depending on the value of argument 3.

    When, static evaluates to true (which occurs for almost all non-nil values), it indicates that the display should be value-based instead of time-based. This is used for things such as Power and Health triggers. In this mode, duration and expirationTime would be more accurately thought of as currentValue and maximumValue; the display shows whatever it receives for argument 1 as the "progress" text, and uses arg1/arg2 as its percentage progress.

    When static evaluates to a function, the display references that function and uses it in its OnUpdate handler, which means it uses that function to obtain a new update for the display's duration info every time a screen frame is drawn*. This is used most specifically for Power triggers, because the values returned by UnitPower() calls actually update much more frequently than UNIT_POWER events occur, and people are used to seeing that fast updating on mana bars.

    However, all that is said just for future reference. You do not want to define static in the first place. When static is false or nil, the display treats duration and expirationTime very differently. In this case, duration represents the total duration of an aura or timed event (in your case, it would be 50), and expirationTime represents the time at which the aura or timed event would end normally. If your 50-second aura has just been applied, this would be GetTime() + 50. When duration info is defined in this way, the display itself will both calculate its progress percentage and format its displayed duration text automatically.

    So, it would behoove you to change your duration function to this:

    function()
        return 50, WeakAuras_Polymorph_Start + 50
    end
    

    Now, I'm not going to guarantee this will solve all your problems. It will definitely make the duration text look cleaner, but the problems with values not updating correctly on Polymorph refresh may or may not be related. Thankfully, my main is a mage, so unlike a lot of problems that are presented to me on this forum, I can test this directly.


    *This method of defining the OnUpdate handler is extremely inefficient, because of the way Lua handles function scoping and creation. A new function closure is created every time the trigger is tested, which could be every few seconds or more. In 1.4, an option was added to define static as a string instead of a function. The contents of the string are ignored; the type of the variable itself indicates that the original duration function should be passed to displays as the OnUpdate function, which accomplishes the same goal but without a new closure of the function being created every time the trigger is tested.

    TL;DR: when you want define a fast-updating duration info, just use a string for argument 3.


    In case you were wondering: argument 4, inverse, is used to indicate that a Progress Bar or Progress Texture should progress backwards. It was added specifically to support Cast triggers, so that casted spells and channeled spells could move in different directions at the discretion of the trigger itself. It is also used for Death Knight Rune triggers, just because it makes them look better.

    #3 May 31, 2011 at 01:05 UTC - 0 likes

    Thanks for the explanation of what the duration function should return. I wasn't able to find any documentation on it, so I just pulled the return type from the discussion of the modified mana bar. Are these custom functions documented somewhere for future reference?

    Once I changed the duration function to your suggestion, cleaned up the custom trigger to make it return true on a refresh, and moved the effectful code from the untrigger function to a custom OnHide action (to take into account the corner case when the polymorph expires while you're too far away to get the dissipation event), everything began behaving as expected. Thanks!

    Currently, my warning display (which shows a texture and plays a warning sound when there is less than 5 seconds remaining) uses a simple customs status trigger that fires on every frame. When no polymorph is active, it fails out immediately with the WeakAura_Polymorph_Start == nil check, so this is definitely efficient enough.

    I'm pretty pleased with the results, so here's the export if anyone is interested:

    dqumlaGiLIrjjoLK0RqKsZII6wQc7scyyiQJjrTmLspJszAuORru2MKY3OinoiY5qeRdrkUhLk7drQoiewOQuEOQinrvrDriQnsK6JsQAKsGCskIvQQMPe0njc7es9tkvnuizPQs1tvzQc5QerBvcuFvvYCjs2lP)QKbl1HrAXsOhtvMmqxw0MfQptunAk40i8AjYSPKBdy3u53Ggov1YH65eMUIRly7is(UQigVKkNxPA)OwlRr6r1iD0tOx5cySaL1dqpq9a1i9ePvmkiHB07n7JISxIcrw6i9ia1df0AxcOJyGy92TpowKJkTrzKTvZMTYKGuzJ2mIesA8dzB1lRZN6atq9n9WPCcOlA3p1togg81Ro7JJf5Os)WOmY2QzZwzsqQSrJKjxwJFiBRo65Prk6YAKEEbXabIY6g9IdoVHa6QuL)CZn3CJZjGDC)kPLqeWuXcf0AhaI9nSKawCHMcK8pDG8N)8N)8N)8N)8N)6TBFCSihv6hYm1uYBTrInKixJSPBrYun(Hrz65fedeikRBK0hKoPEjPs3Oh1BiGoHgPNyO4rJ0deU8cIbcOf1tUf8jRymfi1dHxwVKMerlwpgg8lhrlAth9IjCecdAKEEbXab07vslHiGPIfkO1oae7ByDdfpCBh3ocl()kPLqeWuXcf0AhaI9nSKawCHMcKCBh3ocl9aHlbm4a1I6bcxaPqqLNAr9aHlVGyGa6B6jGbhOEM4Meht9sPqaccDcPEL0sicyQqkuWNKyebmvircsqL6GbhOqkusI(PfubGYLRJo6nyc5YtSgP3S7N65fedeqpVGyGaldeGPEEbXab0dmGPdb0PNmY65fede45aMoeqNEXbN3qaDvQYFU5MB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nbCQN0w0rpQJaGoeqNgPxmHJqyqJ0B29t98cIbcOJo6rddulQxD2hhlYrL(HmtjPwTT1SvUMrB2izljA8dJ20JaupuqR93Oy9Ecb4yqL2uY2QHKPYkVLesiHSntRPXpmktpdjHCdJI2iz9aje(w0Dt8Go9mXnjoM6LszIh0jK68tlRfA6eW5cf0AhaI9nOxrQxj5yyWb(uOfeRrkAJkAYfyRmD0rrVvJ0Ro7JJf5Os)qgsKLzClzsSjJmsKTT1Mg)WOn9cUbtixEI1i98cIbcOxCW5neqxLQ8NBU5MBCobSJBhC4UYRKwcratfluqRDai23W6gkE4M6a5U(CIiaYkv5(b3VsAjebmvSqbT2bGyFdRBO4HBs3oUnkRk)thOo6Ht5eqx0UFQ3K1nbCQxrR0bkbem1dXZpRh1BiGoHgPNyO4rJ0tadoq9mXnjoM6LsHaee6es9kPLqeWuHuOGpjXicyQqIeKGk1bdoqHuVzseYfakxUEGWLagCG6B6OxmHJqyqJ0deU8cIbcOf1ZligiGE8N)6OJEtw3eWPENFAzjKcHWp9MLeqxPCxVbtixEI1i9MD)upVGyGa65fedeyzGam1Biasq9cUKuPB0JggOEEbXabwZUFQNyOtqONxqmqa9IdoVHa6QuL)CZn3CJZjGDC)kPLqeWuXcf0AhaI9nSUHIhUPoqURpNicGSsvUFW9RKwcratfluqRDai23W6gkE4M0TJBJY4F6a5p)5p)5p)5p)5p)5p)5p)1liYvWrm6B65zi9kPxWhKoPo6raQhkO1(lk2PNfKcQr6fe5YLKkXArD0B3(4yroQ0pKrcsLTzejJLrY0TY2wJSg)WynD0rpsPOlBKmzDuf
    
    Last edited May 31, 2011 by Ikcelaks
    #4 May 31, 2011 at 05:41 UTC - 0 likes
    Quote from Ikcelaks:

    I wasn't able to find any documentation on it, so I just pulled the return type from the discussion of the modified mana bar.

    Yes, unfortunately, I am often too lazy to write documentation for new advanced features. At least I'm usually around to provide an in-depth explanation on the forum.

  • 4 posts

You must login to post a comment. Don't have an account? Register to get one!