Thread Tools Display Modes
05-18-13, 06:19 PM   #1
10leej
A Molten Giant
 
10leej's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2011
Posts: 583
FontString for value and percent?

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:
  1. frame = f:CreateFontString(nil,"ARTWORK","GameFontHighlight")
  2. frame:SetPoint("BOTTOM",frame,0,0)
  3. frame:SetText("health text")
wouldn't mind having something like this, course that example is using the script I have above
Attached Thumbnails
Click image for larger version

Name:	Capture.PNG
Views:	348
Size:	301.2 KB
ID:	7713  
__________________
Tweets YouTube Website

Last edited by 10leej : 05-18-13 at 06:36 PM.
  Reply With Quote
05-18-13, 09:43 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
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")
f.HealthText:SetPoint("BOTTOM")
Then whenever you want to make it show some other text, just set its text:

Code:
f.HealthText:SetText("15%")
If your text involves any string.format or concatenation, use :SetFormattedText instead of :SetText to move the formatting C-side:

Code:
local currentHealth, maxHealth = UnitHealth("player"), UnitHealthMax("player")
f.HealthText:SetFormattedText("%d/%d", currentHealth, maxHealth)
__________________
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.
  Reply With Quote
05-18-13, 11:04 PM   #3
10leej
A Molten Giant
 
10leej's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2011
Posts: 583
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:
  1. f.HealthText = f:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  2. f.HealthText:SetPoint("BOTTOM",f.hp,0,0)
  3. local currentHealth, maxHealth = UnitHealth("player"), UnitHealthMax("player")
  4. local function update(self)
  5.   local unit = self.unit
  6.   f.PowerText:SetFormattedText("%d/%d", currentPower, maxPower)
  7. f:SetScript("OnEvent",update)
  8. f:RegisterUnitEvent("UNIT_HEALTH",f.unit)
  9.  
  10. update(f) --initial update
__________________
Tweets YouTube Website

Last edited by 10leej : 05-18-13 at 11:10 PM.
  Reply With Quote
05-19-13, 04:56 AM   #4
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,246
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.
  Reply With Quote
05-19-13, 05:05 AM   #5
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Also UnitHealth and UnitHealthMax need to be inside of the update function or their values will never change.
  Reply With Quote
05-19-13, 06:15 AM   #6
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by myrroddin View Post
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.
Some men, just want to watch the taints burn.
  Reply With Quote
05-19-13, 09:04 AM   #7
10leej
A Molten Giant
 
10leej's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2011
Posts: 583
Originally Posted by Resike View Post
Some men, just want to watch the taints burn.
But, I like tainting everything !

MWAHAHAHAHAHAHAHAHAHAHHAHAHAHA
__________________
Tweets YouTube Website
  Reply With Quote
05-24-13, 02:12 PM   #8
Aanson
A Flamescale Wyrmkin
Join Date: Aug 2009
Posts: 124
Haha!! I'm sure it's 6 and half a dozen
__________________
__________________
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » FontString for value and percent?


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