oUF checks if the unit you registered the tag for has a target suffix (focustarget, pettarget, targettarget and so on - maintank and mainassist are not checked against, I was wrong about it in my previous post, sorry for that) or whether a frequentUpdates field is set on the font object for the tag or . If any of this conditions are met, oUF looks if frequentUpdates resolves to a number and, if so, it uses this number as the update timer or a default value of 0.5 else (meaning update twice a second).
Let's test what you describe.
1. Create the health tag function:
lua Code:
oUF.Tags.Methods["layoutName:healthTag"] = function(unit)
print(date("%X"), "healthTag", unit) -- we use this for debug
if (not UnitIsConnected(unit) or UnitIsDeadOrGhost(unit)) then return end
return UnitHealth(unit)
end
oUF.Tags.Events["layoutName:healthTag"] = "UNIT_HEALTH UNIT_MAXHEALTH"
2. Create the font object and add the tag to it:
Lua Code:
local healthValue = self.Health:CreateFontString(nil, "OVERLAY")
healthValue:SetFont(fontName, fontHeight, fontStyle)
healthValue:SetPoint("TOPRIGHT", self.Health, -3.5, -3.5)
healthValue.frequentUpdates = 2 -- this means update every 2 seconds
self:Tag(healthValue, "[layoutName:healthTag]")
self.Health.value = healthValue
3. Make sure you set the above for the player frame
The client gets UNIT_HEALTH only if there is a change in the unit's health. So, without using frequentUpdates we would get the output of our print in the health tag only when we loose or gain health. If we are at full health, we shoud see the print only when oUF refreshes the unit (vehicle enter/exit, PLAYER_ENTERING_WORLD ...). If we use frequentUpdates as defined above, we should see the print every 2 seconds, regardless of whether a change in health occurred (date("%X") will let you verify that, as long as the update timer is not a fraction of a second).
The bottom line is, UNIT_HEALTH_FREQUENT is better than using frequentUpdates, as you get the event only when a change in health occurs. With frequentUpdates you will call UnitHealth(unit) from within your health tag function a lot of times to get maybe redundant information. UNIT_HEALTH_FREQUENT fires about 10 times as often as UNIT_HEALTH (that may have changed since the last time I checked).