|
02-28-14, 05:14 AM | #1 |
Health Text Code Optimization
Good morning,
the following segment of code is working exactly as intended, it just feels rather awkward, particularly the hcur = UnitHealth('player') or UnitHealth('vehicle') in the UNIT_HEALTH event. I imagine there's a better way to do this, any help would be greatly appreciated: Lua Code:
|
|
02-28-14, 09:31 AM | #2 |
First things first, you aren't grouping your conditions.
Lua Code:
Lua Code:
I would personally replace Lua Code:
Lua Code:
The main time you would want to check the event is if you're watching something like UNIT_HEALTH_FREQUENT which fires very frequently and want to reduce how much you're doing in response to that event. |
|
02-28-14, 07:40 PM | #3 |
As a follow up I have found one thing that doesn't work:
I've tried debugging but that only makes me even more confused. I am testing this by falling to my death. When I hit the ground my chat frame will print: (dead "PLAYER_DEAD") yet the health text remains '0' If I reload ui while dead (without releasing) it will print (dead "PLAYER_ENTERING_WORLD") and the health text will show 'Dead' I don't get how the event can fire and the text isn't updated, requiring a reloadui to truly update the text. The entire function now reads: Lua Code:
|
|
02-28-14, 10:38 PM | #4 |
That's an awful lot of unnecessary event checking.
You don't need to listen for PLAYER_DEAD and PLAYER_ALIVE at all, as UNIT_HEALTH will fire for the player unit at those times anyway. You don't need UNIT_ENTERING_VEHICLE and UNIT_EXITING_VEHICLE, as you only care when those transitions end, not when they begin. Lua Code:
I'm fairly sure, but not 100% sure, that UNIT_HEALTH will fire anyway when you enter or leave a vehicle, so you don't actually need to register for those events. However, if that's not the case, just register ENTERED and EXITED to tell you when those transitions end, and adjust the event handler as follows: Code:
+ if event == "UNIT_ENTERED_VEHICLE" then + unit = "vehicle" + end local hcur, hmax = UnitHealth(unit or "player"), UnitHealthMax(unit or "player")
__________________
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. |
|
03-01-14, 11:16 AM | #5 |
I thank you, yet again, for your assistance, there were a few things I needed to change:
the unitisghost had to be changed to say ghost and not dead, and the unitisdead had to be changed to dead and not ghost :P second, the previous code was comparing a formatted text to a number It would add k or m and round the number and then compare, resulting it always giving a red number as they could never be the same upon entering a vehicle the UNIT_HEALTH event does not suffice unfortunately and the event check had to be added making the end code this: Lua Code:
|
|
WoWInterface » Developer Discussions » General Authoring Discussion » Health Text Code Optimization |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Switch to Linear Mode |
Hybrid Mode |
Switch to Threaded Mode |
|
|