WoWInterface - View Single Post - Accessing fontstring from secure snippet
View Single Post
03-24-18, 12:39 AM   #4
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Ethly View Post
It seems that the proper way to update unit information is OnAttributeChanged handler.
That will only update the frame once, when the unit is first set (e.g. to "target"). If you click on another unit to change your target, the unit attribute doesn't change (it's still "target") so you'd still be showing the name of the previous target. For raid frames, this means that as group members change, your frames won't appear to update.

The proper way is to register for specific events that indicate specific information changes, and update only the relevant portions of your frame when they fire. For example, update the name string when UNIT_NAME_UPDATE fires; the level string when UNIT_LEVEL fires; the health bar when UNIT_HEALTH, UNIT_HEALTH_FREQUENT, or UNIT_MAXHEALTH fire; etc. See the unit events list on Wowpedia for a list of relevant events. Also, use RegisterUnitEvent(event, unit) instead of RegisterEvent(event) so that your frame only receives events for the unit it's displaying.

For some frames, you'd also want to update everything when certain events fire -- for example, for a target frame, you'd need to listen for PLAYER_TARGET_CHANGED to know when you selected a different target, since e.g. UNIT_NAME_UPDATE doesn't fire in that case (the unit's name didn't change when you targeted it!).

Finally, "*target" units (targettarget, focustarget, raid12pettarget, etc.) don't fire unit events at all, so you just have to update everything in an OnUpdate handler. You can look at how oUF handles these events for an example.
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