Quantcast
RegisterUnitEvent vs RegisterEvent - WoWInterface
Thread Tools Display Modes
12-20-13, 12:08 AM   #1
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 453
RegisterUnitEvent vs RegisterEvent

I noticed something strange today. If you use RegisterEvent("UNIT_PET") and summon a warlock demon, you get the event 4 times (the first argument is all 4 times "player"). If you use RegisterUnitEvent("UNIT_PET", "player") you only catch the 2nd and the 3rd time. Why would that be the case? A bug?
  Reply With Quote
12-20-13, 02:46 AM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
I vaguely recall UNIT_PET being an annoying event in general, from back when I wrote CreatureComforts for my (long since retired now) hunter. As far as I could ever tell it fires multiple times as the pet is progressively loaded... once for "unit now exists, but everything about it is unknown", once for "okay, you can now get the pet's name and other info, but it's not fully loaded yet", and finally for "okay, now it's loaded, you can get its health and everything!" I ended up having to keep track of the state in a flag so I could ignore the irrelevant events and avoid doing a bunch of expensive processing.

Same goes for dismissing -- once for "it's despawned" and then another for "the unit no longer resolves".

You can see the effects of this even on the default unit frames. When you summon a pet, the frame appears but is grayed out, then a second later fills in with health and such. When dismissing, it goes in reverse, grays out, then disappears a second later.

I'm not sure why RegisterUnitEvent would pass through fewer events, but I'd have to say fewer events is a step in the right direction (one event would be ideal) so I wouldn't worry about it too much.
__________________
Author/maintainer of Grid, PhanxChat, oUF_Phanx, and many more.
Troubleshoot an addon Turn any code into an addon More addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please dont PM me about addon bugs or code questions. Post a comment or forum thread instead!
  Reply With Quote
12-20-13, 09:12 AM   #3
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 453
Exactly the behavior you mention is the reason it has an implication for what I am trying to do, as the pet spells become available between the 3rd and 4th time the event fires (there is a specific SPELLS_CHANGED for that), so IsSpellKnow(id, true) just returns false if I use RegisterUnitEvent. There is an easy solution to that in my case and it was easy to spot the problem as I had some other code tracking pet spells that was functional. This just opens the question how safe is it to use RegisterUnitEvent?
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » RegisterUnitEvent vs RegisterEvent

Thread Tools
Display Modes

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