WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   bXP Error (https://www.wowinterface.com/forums/showthread.php?t=50376)

Mirrikh 11-06-14 06:26 AM

bXP Error
 
I seem to be getting this error from the xp addon I'm using
Code:

bXP\bXP-1.0.lua:98: attempt to call global 'formatNumber' (a nil value)
bXP\bXP-1.0.lua:98: in function <bXP\bXP.lua:65>

not sure how to fix
Here's the relevant code
Code:

bar:SetScript("OnEvent", function()
    xp = UnitXP("player")
    mxp = UnitXPMax("player")
    rxp = GetXPExhaustion("player")
    name, standing, minrep, maxrep, value = GetWatchedFactionInfo()
   
    xpbar:SetMinMaxValues(0,mxp)
    if UnitLevel("player") == MAX_PLAYER_LEVEL or IsXPUserDisabled == true then
        if name then
            xpbar:SetStatusBarColor(FACTION_BAR_COLORS[standing].r, FACTION_BAR_COLORS[standing].g, FACTION_BAR_COLORS[standing].b, 1)
                        xpbar:SetMinMaxValues(minrep,maxrep)
                        xpbar:SetValue(value)
                        xpbar.text:SetText(value-minrep.." / "..maxrep-minrep.." | "..floor(((value-minrep)/(maxrep-minrep))*1000)/10 .."% | ".. name)
            bar:Show()
        else
                        bar:Hide()
        end
    else
        xpbar:SetStatusBarColor(unpack(config.color))
                xpbar:SetValue(xp)
                if rxp then
                        xpbar.text:SetText(format(xp).." / "..format(mxp).." | "..floor((xp/mxp)*1000)/10 .."%" .. " (+"..format(rxp)..")")
                        xpbar:SetMinMaxValues(0,mxp)
                        xpbar:SetStatusBarColor(unpack(config.restedcolor))
                        xpbar:SetValue(xp)
                        if (rxp+xp) >= mxp then
                                rxpbar:SetValue(mxp)
                        else
                                rxpbar:SetValue(rxp+xp)
                        end
                        rxpbar:Show()
                        bar:Show()
                elseif xp then
                        xpbar.text:SetText(formatNumber(xp).." / "..formatNumber(mxp).." | "..floor((xp/mxp)*1000)/10 .."%")
                        rxpbar:Hide()
                end
    end
end)


Choonstertwo 11-06-14 06:43 AM

The code is trying to call the function formatNumber, which doesn't exist in the scope of that statement. Is this function defined anywhere in the AddOn?

Mirrikh 11-06-14 06:50 AM

only in that bit of code is it used.

Choonstertwo 11-06-14 07:04 AM

The part of the function that handles rested XP appears to be using the format function to format its numbers, so you should probably use that for the non-rested part as well.

Is the format function defined by the AddOn or is it using the global alias of string.format? The latter would be pointless.

Mirrikh 11-06-14 07:07 AM

I'm not too sure (not too good with lua), but I don't think it's defined by either.

Here's all the code.

Choonstertwo 11-06-14 07:23 AM

That code doesn't seem to be very well written, it's leaking quite a few globals.

You'll want to replace the calls to format and formatNumber with BreakUpLargeNumbers.

You'll also want to replace IsXPUserDisabled == true with IsXPUserDisabled() (it's a function, not a boolean).

I'm not sure why the code is using format with a single numeric argument unless it used to be something other than an alias of string.format (which I don't think is the case).

Mirrikh 11-06-14 07:39 AM

Thank you, that seems to have fixed it. Yea, it's kind of an old (not updated) addon, but it does what I like.


All times are GMT -6. The time now is 11:51 AM.

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