WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   oUF (Otravi Unit Frames) (https://www.wowinterface.com/forums/forumdisplay.php?f=87)
-   -   oUF_Phanx different text sizes for health values? (https://www.wowinterface.com/forums/showthread.php?t=45668)

Expunge 01-16-13 04:56 PM

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!

Phanx 01-16-13 05:46 PM

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)

Expunge 01-16-13 05:53 PM

Quote:

Originally Posted by Phanx (Post 271965)
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!


All times are GMT -6. The time now is 10:02 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI