Originally Posted by siweia
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:
local function OnTargetChanged(frame)
-- do stuff when the target changed, regardless if this frame represents the new target
if UnitIsUnit(frame.unit, 'target') then
-- the frame is the new target
else
-- the frame is something else than the new target
end
end
oUF:RegisterStyle('MyStyle', function(self, unit)
self:RegisterEvent('PLAYER_TARGET_CHANGED', OnTargetChanged)
end)
oUF:SpawnNamePlates('MyStyle', OnTargetChanged)