Thread Tools Display Modes
08-20-13, 10:16 AM   #1
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
Passing events to tag functions

Currently a tag function receives two arguments: the unit and the realUnit (if self.overrideUnit is set) the tag is registered for. Is there a way to add the event the tag is being updated upon to the list of arguments?
  Reply With Quote
08-20-13, 11:31 AM   #2
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
It could be added as global in the tag functions environment, but is it really necessary?
__________________
「貴方は1人じゃないよ」
  Reply With Quote
08-20-13, 11:48 AM   #3
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
I've encountered a situation where UnitClass returns nil when people join a party. I update the tag at UNIT_NAME_UPDATE, UNIT_FACTION and UNIT_CONNECTION and would like to know when this is the case. Apart from that one could further customize tags based on what event fired.

Would you give me some pointers how to add this as I must admit I barely understand the tags element.
  Reply With Quote
08-20-13, 01:00 PM   #4
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
I don't really see how it would help, but something simple like this should work:
Code:
diff --git a/elements/tags.lua b/elements/tags.lua
index 9826269..76e8c2d 100644
--- a/elements/tags.lua
+++ b/elements/tags.lua
@@ -416,11 +416,14 @@ local frame = CreateFrame"Frame"
 frame:SetScript('OnEvent', function(self, event, unit)
        local strings = events[event]
        if(strings) then
+               _ENV.event = event
                for k, fontstring in next, strings do
                        if(fontstring:IsVisible() and (unitlessEvents[event] or fontstring.parent.unit == unit)) then
                                fontstring:UpdateTag()
                        end
                end
+       else
+               _ENV.event = nil
        end
 end)
Then you can access the event by just checking: if event == "EVENT_NAME" then ... end
__________________
「貴方は1人じゃないよ」
  Reply With Quote
08-20-13, 02:00 PM   #5
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
Thank you for that, haste. I'll have a look into my code as the powerbars of the party frames color correctly by class but my name tags don't. It's pretty seldom though and I don't have a sure path to reproduce it, that's why I wanted to have the event.
  Reply With Quote
08-20-13, 02:04 PM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Rainrider View Post
I've encountered a situation where UnitClass returns nil when people join a party. I update the tag at UNIT_NAME_UPDATE, UNIT_FACTION and UNIT_CONNECTION and would like to know when this is the case.
Code:
local f = CreateFrame("Frame")
f:RegisterEvent("UNIT_NAME_UPDATE")
f:RegisterEvent("UNIT_FACTION")
f:RegisterEvent("UNIT_CONNECTION")
f:SetScript("OnEvent", function(f, event, unit)
    if not UnitClass(unit) then
        print("UnitClass returned nil for", unit, "on", event)
    end
end)
Leave that running in the background for a while and see what it says.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Passing events to tag functions


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off