WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   oUF (Otravi Unit Frames) (https://www.wowinterface.com/forums/forumdisplay.php?f=87)
-   -   Totem Tag - help needed (https://www.wowinterface.com/forums/showthread.php?t=48654)

Pyrates 12-11-13 01:01 PM

Totem Tag - help needed
 
Hi all!

Can someone tell me what's wrong with the following tag?

Code:

oUF.Tags.Methods["shrooms"] = function(u)
        local count = 0
        for i=1,3 do
                local _,_,_,dur = GetTotemInfo(i)
                if dur > 0 then
                        count = count + 1
                end
        end

        local color = cfg.colors.power.CP[2*count-1]

        if count == 0 then
                return("")
        else
                return ("|cFF%.2x%.2x%.2x%s|r"):format(color[1] * 255, color[2] * 255, color[3] * 255, count)
        end
end
oUF.Tags.Events['shrooms'] = 'PLAYER_TOTEM_UPDATE'
oUF.Tags.SharedEvents["PLAYER_TOTEM_UPDATE"] = true

I've confirmed the the fontstring it's tagged on is there and shows up if I set a text, the event fires properly... I'm at a loss. Thanks for any help!

Phanx 12-11-13 04:36 PM

Do you have Lua errors turned on or BugSack installed?

Pyrates 12-12-13 12:30 PM

Yes I do. None whatsoever.

Btw, I just came back after a 2y break, and I remember you (esp. for being helpfull). Nice to see you around still :)

Phanx 12-12-13 06:46 PM

Actually on second glance, I think this is your problem:

Code:

("|cFF%.2x%.2x%.2x%s|r"):format(color[1] * 255, color[2] * 255, color[3] * 255, count)
%.2x does not guarantee a 2-digit result; it guarantees a result with no more than 2 digits after the decimal point. You want to use %02x instead.

For example, format("%02f", 10 / 3) == "03.33333333333333333", but format("%.2f", 10 / 3) == "3.33". So, if your color values are 1, 0.5, and 0 then you're converting them into ff (ok), 99 (ok) and 0 (not ok) to end up with "|cffff990<<count>>|r" which isn't a valid color code. Technically you are producing a valid color code when combined with your count, since 1, 2, and 3 are valid hexadecimal values -- "|cffff9903|r" -- but then you don't have any text to display. :p

Also, ("text"):format(...) is the slowest possible method of formatting a string. Use format("text", ...) instead:

Code:

return format("|cff%02x%02x%02x%s|r", color[1] * 255, color[2] * 255, color[3] * 255, count)

Pyrates 12-13-13 12:21 PM

Thanks for your suggestions. I tried it, but to no avail :( I also inserted a print statement, and it seems clear to me the function is never called. I did confirm PLAYER_TOTEM_UPDATE fires when I plant a mushroom... might have something to do with the unitless events, but I have no idea how to check for that.

I did run this script ingame:
Code:

local event = 'PLAYER_TOTEM_UPDATE'
for i = 1, select( "#", GetFramesRegisteredForEvent(event)) do
 local frame = select(i,GetFramesRegisteredForEvent(event))
 print(frame:GetName())
local func1 = frame:GetScript("OnEvent")
print(func1)
end

It printed "TotemFrame" and a function number... seems reasonable enough, but I don't know where to go from here. I tried running "func1("PLAYER_TOTEM_UPDATE",1)", but that didn't do anything...

(e) I just remembered, there's another tag that's not working. I didn't want to ask 2 questions at once, but maybe they're connected? The other tag is

Code:

oUF.Tags.Events['BossBars:health'] = oUF.Tags.Events["curhp"] .. " " .. oUF.Tags.Events["maxhp"]
oUF.Tags.Methods['BossBars:health'] = function(unit)
                local m = UnitHealthMax(unit)
                if(m == 0) then
                        return 0
                else
                        return math.floor(UnitHealth(unit)/m*100+.5)
                end
end

It's "somewhat" working in that it shows HP percent, but it only updates when I change target. Seems some events don't reach their functions? Strange, the other tags seem to work just fine (and the healthbar of that unit works nicely as well).

Phanx 12-13-13 06:17 PM

Well here is an example tag from my own layout that is definitely working with a "unitless" event:

Code:

oUF.Tags.Events["restingicon"] = "PLAYER_UPDATE_RESTING"
oUF.Tags.SharedEvents["PLAYER_UPDATE_RESTING"] = true
oUF.Tags.Methods["restingicon"] = function(unit)
        if unit == "player" and IsResting() then
                return [[|TInterface\CharacterFrame\UI-StateIcon:0:0:0:-6:64:64:28:6:6:28|t]]
        end
end

Based on that, here is how I would write a mushroom counter tag (with your coloring):

Code:

oUF.Tags.Events["mushrooms"] = "PLAYER_TOTEM_UPDATE"
oUF.Tags.SharedEvents["PLAYER_TOTEM_UPDATE"] = true
oUF.Tags.Methods["mushrooms"] = function(unit)
        if unit == "player" then
                local count = 0
                for i = 1, MAX_TOTEMS do
                        local _, _, _, duration = GetTotemInfo(i)
                        if duration > 0 then
                                count = count + 1
                        end
                end
                print("UPDATE TAG: mushrooms", count)
                if count > 0 then
                        local color = cfg.colors.power.CP[2 * count - 1]
                        return format("|cff%02x%02x%02x%d|r", color[1] * 255, color[2] * 255, color[3] * 255, count)
                end
        end
end

I don't have a druid to test that on, though.

For your health tag, I suspect the problem is the way you are listing events. Rather than concatenating the events from other tags (which may or may not be defined yet when your code runs) just write out the events; there are only two of them. Also, you don't need to explicitly return an empty string or a zero if there's no value; just don't return anything, and the fontstring will be emptied.

Code:

oUF.Tags.Events["BossBars:health"] = "UNIT_HEALTH UNIT_MAXHEALTH"
oUF.Tags.Methods["BossBars:health"] = function(unit)
        local m = UnitHealthMax(unit)
        if m > 0 then
                return floor(UnitHealth(unit) / m * 100 + 0.5)
        end
end


Pyrates 12-14-13 08:19 AM

I tried the things you suggested, to no avail... this is all very strange. I confirmed that oUF.Tags.Events and oUF.Tags.SharedEvents contain the right entries for the mushrooms tag, and oUF.Tags.Methods["mushrooms"] is the right function (I can execute it and then read the print statement). I can _also_ see that the function that Totem_Frame has registered for OnEvent is _not_ the one from oUF.Tags.Methods["mushrooms"]. Probably because of oUF internals, but executing that OnEvent function does not print anything... I also changed the function to function(), because PLAYER_TOTEM_UPDATE does not give an argument (so unit would be nil), but that also didn't change anything.

As for the BossBars:health tag, there's no entry in oUF.Tags.Events or oUF.Tags.Methods for it, so I'll have to see if dependencies are right and the code gets executed. Funky though that the tag updates at all, and the unitframe itself works nicely.

(e) Wait, I got an idea. I use Tukui, which brings it's own version of oUF, but I don't use the unitframes, so I've installed oUF itself, too. I bet there's some kind of conflict going on. I'll sort that out tonight and then report if the problem persists. Thanks for helping so far!

Pyrates 12-14-13 02:31 PM

Hrrmmm, I resolved it, but it doesn't really change a lot, since the ouf from tukui lives in its own namespace. I made the bossbars use the standard ouf, so I can now find the tag's entries in oUF.Tags and its subtables correctly. Still, both tags don't work, just as I described above.

The only additional info that I found is that the bosshealth tag doesn't really update when I change targets, but only when I target the boss in question. Given that the entries in oUF.Tags and its subtables look totally correct, I find that really weird.

Now, I'd still be grateful for any hints or ideas what to check.

(e) Well well, another thing turns up. I realized there's a tag for hp percentage in stock ouf... so I didn't need my bossbars health tag. So I tagged the fontstring with perhp... and behold, the problem _still_ persists. So it might be a bug in ouf? Still no dice with the mushrooms though...

(ee) Ok, Boss thingy is explained here: http://www.wowinterface.com/forums/s...ad.php?t=46127

Phanx 12-14-13 09:30 PM

Quote:

Originally Posted by Pyrates (Post 288191)
Hrrmmm, I resolved it, but it doesn't really change a lot, since the ouf from tukui lives in its own namespace. I made the bossbars use the standard ouf, so I can now find the tag's entries in oUF.Tags and its subtables correctly. Still, both tags don't work, just as I described above.

That's not really a good solution... just find the global TukUI's oUF is using, and replace "oUF.Tags" with "whatever.Tags".

Quote:

Originally Posted by Pyrates (Post 288191)
The only additional info that I found is that the bosshealth tag doesn't really update when I change targets, but only when I target the boss in question. Given that the entries in oUF.Tags and its subtables look totally correct, I find that really weird.

I'd forgotten about that... on one hand, I can't believe Blizzard hasn't fixed that bug yet. On the other hand, it's Blizzard, so I'm not really surprised. Fixing UI bugs that don't spam users with popup errors does not seem to be anywhere on their list of priorities. :(

Pyrates 12-15-13 10:39 AM

Quote:

Originally Posted by Phanx (Post 288204)
That's not really a good solution... just find the global TukUI's oUF is using, and replace "oUF.Tags" with "whatever.Tags".

Any reason for that? I _was_ thinking about just having 1x oUF loaded, but it shouldn't really matter, should it?

Anyways, going forward. I manually made a frame, registered PLAYER_TOTEM_UPDATE and set the OnEvent script, and everything worked well. I also realized that by the code above, that event is only registered for TotemFrame, which is from the standard UI. Means, oUF doesn't even register that event, right? So either I'm doing something wrong here or there's a bug somewhere. I'll try to figure out the oUF code on this...

Pyrates 12-15-13 01:40 PM

Well, don't I feel stupid now :( I mean, more than usual...

Here's how I made the fontstring:

Code:

        if TukuiDB.myclass == "DRUID" then
                                self.shrooms = self:CreateFontString(nil, "OVERLAY")
                                self.shrooms:SetFontObject("UFFontMedium")
                                self.shrooms:SetPoint("TOPRIGHT",self,"TOPRIGHT",0,-4)
                                self:Tag(shrooms,"[shrooms]")
                        end

What I do on _all_ other occasions but not here is to first create a local variable, construct the object and set properties and _finally_ set self.variable = variable. But in this one instance, yeah, I don't. I create self.shrooms directly instead of local shrooms and then setting self.shrooms = shrooms. Which makes the above... well, not working. The last line needs to read "self:Tag(self.shrooms,"[shrooms]")".

I found this by traversing ouf's code with print statements. Not trying to blame anyone else for my own stupidity, but is there a reason ouf does not print an error message along the lines of "Dude, your tag's fontstring is nil"?

Anyways, thanks for reading, special thanks to phanx for some handholding. I DID learn quite a bit, so it's not a total loss :)

Phanx 12-16-13 01:00 AM

Quote:

Originally Posted by Pyrates (Post 288228)
... is there a reason ouf does not print an error message along the lines of "Dude, your tag's fontstring is nil"?

Code:

local Tag = function(self, fs, tagstr)
        if(not fs or not tagstr) then return end

As to why it was written that way, I don't know, but it is in line with other oUF element constructors -- none of them will throw an error if you call them for an object that doesn't exist; they'll just silently do nothing.


All times are GMT -6. The time now is 11:02 PM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI