View Single Post
08-11-14, 02:19 AM   #18
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by liquidbase View Post
local XP, maxXP, restXP = UnitXP("player"), UnitXPMax("player"), GetXPExhaustion()
local percXP = ((XP == 0) and (maxXP == 0)) or (math.floor((XP / maxXP) * 100))
That second line is the problem; I don't think it's doing what you think it's doing. What you wrote is the equivalent of this:

Code:
if XP == 0 and maxXP == 0 then
     percXP = true
else
     percXP = floor(XP / maxXP * 100)
end
SDPhantom's suggestion will prevent the error from showing up, but I'd suggest doing this instead:

Code:
local XP, maxXP, restXP = UnitXP("player"), UnitXPMax("player"), GetXPExhaustion()
if not maxXP or maxXP == 0 then return end
local percXP = floor(XP / maxXP * 100)
There's no point in going on with the rest of your display logic if you don't have any valid information to display, or you just end up displaying wrong information.
__________________
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.