Thread Tools Display Modes
01-18-21, 06:54 PM   #1
doofus
A Chromatic Dragonspawn
Join Date: Feb 2018
Posts: 158
UnitHealth refresh

Every so often, sometimes as often as 3-4 times a second, I call UnitHealth(), and it seems it is "slow" to update, whereas the standard Blizzard raid frames are much more responsive. Looking at gamepedia it seems there used to be a UNIT_HEALTH_FREQUENT event that was remoived with 9.0.1 - but the point is that somehow the standard Blizz party/raid frames work very responsively.

Are there other API calls to retrieve the latest HP of a unit that I should be using?
  Reply With Quote
01-18-21, 07:35 PM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
UNIT_HEALTH and UNIT_HEALTH_FREQUENT were rolled into just UNIT_HEALTH.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
01-18-21, 09:16 PM   #3
kurapica.igas
A Chromatic Dragonspawn
Join Date: Aug 2011
Posts: 152
Normally what your see is just a smooth effect, no other events for the UNIT Health
  Reply With Quote
01-19-21, 07:27 AM   #4
doofus
A Chromatic Dragonspawn
Join Date: Feb 2018
Posts: 158
Unfortunately, calling UnitHealth still shows some "old" value when in fact the party/raid frames have already updated fully after a damage or heal, by eye it is even one second delay with just 25ms latency to server, and it happens very often, and not at busy times or places.

That means (to me) that the party frames must be using a different API function to retrieve a unit's HP and update their bars. And I would like to have access to it to if possible?

Oh one more thing. In a party, some players die, and UnitHealth() (and UnitDeadorGhost()) still shows some random value they were at before they died!

Last edited by doofus : 01-19-21 at 07:30 AM.
  Reply With Quote
01-19-21, 10:07 AM   #5
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
I'm pretty sure there is an onupdate handler for them?
https://github.com/tomrus88/Blizzard...Frame.lua#L305
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
01-19-21, 11:06 AM   #6
doofus
A Chromatic Dragonspawn
Join Date: Feb 2018
Posts: 158
Looking at this code you have posted:

Code:
function CompactUnitFrame_UpdateHealth(frame)
	local health = UnitHealth(frame.displayedUnit);
	if ( frame.optionTable.smoothHealthUpdates ) then
		if ( frame.newUnit ) then
			frame.healthBar:ResetSmoothedValue(health);
			frame.newUnit = false;
		else
			frame.healthBar:SetSmoothedValue(health);
		end
	else
		PixelUtil.SetStatusBarValue(frame.healthBar, health);
	end
end
It seems the "frame" has some "smoothHealthUpdates" functionality (how is that even determined?), but the actual health value comes from "local health = UnitHealth(frame.displayedUnit);"

So he is calling the same function as I am. I only can suspect that addons have lower priority and UnitHealth behaves differently depending on who the caller is ?
  Reply With Quote
01-19-21, 11:34 AM   #7
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
There is no "hidden" magic. It's simply updating not on event but onupdate. So it redraws with every single frame.
https://github.com/tomrus88/Blizzard...Frame.lua#L199
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
01-19-21, 12:54 PM   #8
doofus
A Chromatic Dragonspawn
Join Date: Feb 2018
Posts: 158
That's precisely what I do. I am driven off of frame updates. I am at 75% HP, I cast a heal, the UI shows 100% HP, UnitHealth() reads 85% or some other random figure for a few seconds.
  Reply With Quote
01-19-21, 04:55 PM   #9
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
Maybe there is similar situation that UnitLevel has.

https://wow.gamepedia.com/API_UnitLevel
'Note that the value returned by UnitLevel("player") will most likely be incorrect when called in a PLAYER_LEVEL_UP event handler, or shortly after leveling in general. Check the PLAYER_LEVEL_UP payload for the correct level.'

Maybe with UnitHealth you need to use the UNIT_HEALTH event and check the value at that point ? You've not confirmed if you are using UNIT_HEALTH to track health changes. It may be that if you call UnitHealth() and then the health is updated, the screen may show the new value but UnitHealth grabbed the previous value.
__________________
  Reply With Quote
01-19-21, 05:07 PM   #10
Taudier
A Wyrmkin Dreamwalker
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 53
Originally Posted by doofus View Post
That's precisely what I do. I am driven off of frame updates. I am at 75% HP, I cast a heal, the UI shows 100% HP, UnitHealth() reads 85% or some other random figure for a few seconds.
do you have SetCVar("predictedHealth",1) ?
  Reply With Quote
01-19-21, 06:53 PM   #11
doofus
A Chromatic Dragonspawn
Join Date: Feb 2018
Posts: 158
I do not use the event, my code runs off the screen update.

Definitely there is a timing issue, I call UnitHealth() too quick after casting heal or damage, and I get the wrong value.

But I have also observed the wrong value 3-4 seconds in, so this is not timing.

Unfortunately I tried again just now and could not reproduce it.

I have not knowingly messed with "predictedHealth", but I did mess with it just now and do not know what the proper value should be, 0 or 1?
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » UnitHealth refresh

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