FontString for value and percent?
1 Attachment(s)
How would I go about this? Never dealt with FontStrings before (my UI uses whoa unitframes, which I have no idea as to what I'm looking at when i look there)
I know a basic fontsring can be done doing this Lua Code:
|
I'm not really sure what you're looking for. The code you posted should work, though you probably want to give it a more useful name so you can access it later:
Code:
f.HealthText = f:CreateFontString(nil, "ARTWORK", "GameFontHighlight") Code:
f.HealthText:SetText("15%") Code:
local currentHealth, maxHealth = UnitHealth("player"), UnitHealthMax("player") |
I'm making health text for a HUD addon I'm working on I got the bars updating I just gotta work on the text that I've honestly never dealth with before.
Then if I want the numbers to run and update with health changes I can just do this? Lua Code:
|
Are you assigning currentHealth/maxHealth or currentPower/maxPower? Your code retrieves the former and (fails to display) the latter.
Also, whether you use "frame" or "f" please, for the love of the Light, make that a local variable. |
Also UnitHealth and UnitHealthMax need to be inside of the update function or their values will never change.
|
Quote:
|
Quote:
MWAHAHAHAHAHAHAHAHAHAHHAHAHAHA |
If i-taint worth tainting i-taint worth doing :p
|
Anyways I got it working now for the value text, how do I get it to show percentage as well? (I honestly can't find information on it so I'm sorry to bother you guys)
I imagine it's simply just make another frame for the text but rather than using "%d/%d" just use something else (not sure what though) Lua Code:
|
Why are your variables named currentHealthPercent and maxHealthPercent. They're just your current and max health. Don't create misleading variable names.
To do the percent, you just calculate it. (ie, divide and x100) |
1 Attachment(s)
Quote:
But, I did finally get the text working, thanks for the help everyone! |
Code:
f:SetScript("OnEvent", function(self, event, unit) Code:
f:GetScript("OnEvent")(f, "UNIT_HEALTH", f.unit) |
Seems you code doesn't update the statusbars for 5.3 but the fontstrings do. Not sure why yet as I'm not getting any errors need to do some more testing with it
|
Well, there is nothing in that code that does anything to any statusbar, so that seems correct.
|
Quote:
|
I don't know what others would think about this, but if I was setting up a HUD, I would personally do:
1. Only the health bar and power/mana bar get their values from the UnitHealth("player"), UnitHealthMax("player"), and the power/mana equivalent funcs. 2. I would then hook everything else, including text to the OnValueChanged() handler of the bars. That way, only 1 object is calling the health funcs and the same on the power/mana side. I say this because you said you have the bars set up already, so presumably you're addOn is already being fed all the information that it needs. Hope that makes sense. |
Why hook your own code when you can just save the value to a variable? ;)
|
Quote:
It makes little difference though because you'd still need to be constantly updating the value of your UpValues anyway. Hooking to OnValueChanged just seems like the cleanest way to me. ie. Lua Code:
|
NO DON'T DO THIS TO ME I already got the fontstrings working as they are, not gonna fix it if they ain't broke, lmao
|
Haha!! I'm sure it's 6 and half a dozen :)
|
All times are GMT -6. The time now is 04:07 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI