WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   attempt to compare number with nil (https://www.wowinterface.com/forums/showthread.php?t=58540)

Nattugglan 01-10-21 05:40 AM

attempt to compare number with nil
 
Getting the "error attempt to compare number with nil" with my very simply weakaura that shows my rested experience.

Error:
12x [string "--[==[ Error in 'DataTexts-Rested%':'custom..."]:5: attempt to compare number with nil
[string "=[C]"]: in function `xpcall'
[string "@WeakAuras\WeakAuras-3.1.8.lua"]:4073: in function `RunCustomTextFunc'
[string "@WeakAuras\RegionTypes\Text.lua"]:219: in function `FrameTick'
[string "@WeakAuras\RegionTypes\RegionPrototype.lua"]:646: in function <...aceWeakAuras\RegionTypes\RegionPrototype.lua:638>

My code:
function()
local restedxp = GetXPExhaustion()
local totalXP = UnitXPMax("player")
if restedxp == 0 then return end
if restedxp > 0 then percent = floor((restedxp / totalXP) * 100) end

local ret = string.format("%d%%", percent)
return ret
end

Need help please! : )

LudiusMaximus 01-10-21 06:17 AM

GetXPExhaustion returns nil when you are not rested. So instead of

Code:

if restedxp == 0
you have to do

Code:

if restedxp == nil
or just

Code:

if not restedxp

Nattugglan 01-10-21 09:05 AM

Thanks a lot. I will try this immediately


All times are GMT -6. The time now is 01:40 AM.

vBulletin © 2021, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI