View Single Post
03-14-18, 10:06 AM   #11
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
Originally Posted by siweia View Post
I have no idea why I need to update it in two places to make it work.
The function that you pass as a parameter to oUF:SpawnNameplates only fires when a new nameplate is created OR when a nameplate becomes the new target.
This does not mean the function will also run for the nameplate that was the previous target, hence the solution you had to come up with (which IMO is the correct solution).

To sum it up in code:
Lua Code:
  1. local function OnTargetChanged(frame)
  2.     -- do stuff when the target changed, regardless if this frame represents the new target
  3.     if UnitIsUnit(frame.unit, 'target') then
  4.         -- the frame is the new target
  5.     else
  6.         -- the frame is something else than the new target
  7.     end
  8. end
  9.  
  10. oUF:RegisterStyle('MyStyle', function(self, unit)
  11.     self:RegisterEvent('PLAYER_TARGET_CHANGED', OnTargetChanged)
  12. end)
  13.  
  14. oUF:SpawnNamePlates('MyStyle', OnTargetChanged)

Last edited by p3lim : 03-14-18 at 10:10 AM.
  Reply With Quote