#Getting an error from custom code.

1 messages · Page 1 of 1 (latest)

neon bough
#

I'm getting the error code "Integer overflow attempting to store -nan(ind)" from
"function()
local absorb = UnitGetTotalAbsorbs('player')

local percent = math.ceil((UnitHealth('player') + absorb) / UnitHealthMax('player') *100)

if percent > 100 then
    return string.format('|cff00ff00%i',percent) .. '%'
else
    return string.format('%i',percent) .. '%'
end

end
"
But only when I go through a portal (loading screen)

muted vortex
#

Make sure you can never be dividing by zero

chrome escarp
#

UnitHealth and UnitHealthMax are 0 for a bit when in a loading screen after taking a portal.

neon bough
#

I got "integer overflow attempting to store inf" when I tried to add a + 1 before the divide

#

I'm not really adept at LUA coding so I guess I tried a quick fix

chrome escarp
#
function()
    local absorb = UnitGetTotalAbsorbs('player')
    local uh = UnitHealth('player')
    local uhm = UnitHealthMax('player')
    
    if uh > 0 and uhm > 0 then
        local percent = math.ceil((uh + absorb) / uhm *100)
        
        if percent > 100 then
            return string.format('|cff00ff00%i',percent) .. '%'
        else
            return string.format('%i',percent) .. '%'
        end
    else
        return ""
    end
end
neon bough
#

It worked perfectly! Been struggling with that one since Legion!
Thank you very much!