Thread Tools Display Modes
01-10-21, 05:40 AM   #1
Nattugglan
A Defias Bandit
Join Date: Sep 2010
Posts: 2
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! : )
  Reply With Quote
01-10-21, 06:17 AM   #2
LudiusMaximus
A Rage Talon Dragon Guard
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 320
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
__________________
~ Be the change you want to see in the world... of warcraft interface! ~

Last edited by LudiusMaximus : 01-10-21 at 09:15 AM.
  Reply With Quote
01-10-21, 09:05 AM   #3
Nattugglan
A Defias Bandit
Join Date: Sep 2010
Posts: 2
Thumbs up

Thanks a lot. I will try this immediately
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » attempt to compare number with nil

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