Quantcast
oUF_Phanx different text sizes for health values? - WoWInterface
Thread Tools Display Modes
01-16-13, 04:56 PM   #1
Expunge
A Defias Bandit
Join Date: Sep 2008
Posts: 2
oUF_Phanx different text sizes for health values?

Hey guys. I'm trying to do a few things with the health text in this layout, but I'm not having any luck. I want the player, target, and focus frames to have a larger font size than the rest of the layout, but when I add a simple if statement to make the change, the addon doesn't load anymore. I've attached the original code, and the code with my modifications. What am I doing wrong? Is this even possible?

Thanks!

Original
Code:
local health = ns.CreateStatusBar(self, 16, "RIGHT", true)

health:SetPoint("TOPLEFT", self, "TOPLEFT", 1, -1)
health:SetPoint("TOPRIGHT", self, "TOPRIGHT", -1, -1)
health:SetPoint("BOTTOM", self, "BOTTOM", 0, 1)
self.Health = health
Modified
Code:
if unit == "player" or unit == "focus" or unit == "target" then
	local health = ns.CreateStatusBar(self, 16, "RIGHT", true)
else
	local health = ns.CreateStatusBar(self, 8, "RIGHT", true)
end

health:SetPoint("TOPLEFT", self, "TOPLEFT", 1, -1)
health:SetPoint("TOPRIGHT", self, "TOPRIGHT", -1, -1)
health:SetPoint("BOTTOM", self, "BOTTOM", 0, 1)
self.Health = health
Thanks for the help!
  Reply With Quote
01-16-13, 05:46 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
1. Whenever you are writing/modifying code, make sure you have Lua errors turned on. "Not loading" or "not working" means an error is occurring. If you can't see the error, you're basically working in the dark.

2. Your problem is that you are defining "local health" inside the scope of the "if/else/end" check, so once the "if/else/end" block is done, the "health" variable no longer exists, so the following lines that try to do something with the "health" variable don't have anything to work with, and trigger errors about attempting to index nil values.

Change:
Code:
if unit == "player" or unit == "focus" or unit == "target" then
	local health = ns.CreateStatusBar(self, 16, "RIGHT", true)
else
	local health = ns.CreateStatusBar(self, 8, "RIGHT", true)
end
to:
Code:
local health
if unit == "player" or unit == "focus" or unit == "target" then
	health = ns.CreateStatusBar(self, 16, "RIGHT", true)
else
	health = ns.CreateStatusBar(self, 8, "RIGHT", true)
end
or better yet:
Code:
local health = ns.CreateStatusBar(self, (unit == "player" or unit == "focus" or unit == "target") and 16 or 8, "RIGHT", true)
__________________
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
01-16-13, 05:53 PM   #3
Expunge
A Defias Bandit
Join Date: Sep 2008
Posts: 2
Originally Posted by Phanx View Post
1. Whenever you are writing/modifying code, make sure you have Lua errors turned on. "Not loading" or "not working" means an error is occurring. If you can't see the error, you're basically working in the dark.

2. Your problem is that you are defining "local health" inside the scope of the "if/else/end" check, so once the "if/else/end" block is done, the "health" variable no longer exists, so the following lines that try to do something with the "health" variable don't have anything to work with, and trigger errors about attempting to index nil values.

Change:
Code:
if unit == "player" or unit == "focus" or unit == "target" then
	local health = ns.CreateStatusBar(self, 16, "RIGHT", true)
else
	local health = ns.CreateStatusBar(self, 8, "RIGHT", true)
end
to:
Code:
local health
if unit == "player" or unit == "focus" or unit == "target" then
	health = ns.CreateStatusBar(self, 16, "RIGHT", true)
else
	health = ns.CreateStatusBar(self, 8, "RIGHT", true)
end
or better yet:
Code:
local health = ns.CreateStatusBar(self, (unit == "player" or unit == "focus" or unit == "target") and 16 or 8, "RIGHT", true)
Doh. I knew it was something silly like that. Thank you for the help Phanx, love your work!
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » oUF_Phanx different text sizes for health values?

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