WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   bad argument (https://www.wowinterface.com/forums/showthread.php?t=52771)

kawe 09-25-15 01:11 PM

bad argument
 
Code:

Message: Interface\AddOns\oUF_Mu\core\layout.lua:242: bad argument #2 to
'SetFormattedText' (string expected, got boolean)
Time: 09/25/15 21:04:13
Count: 1
Stack: [C]: in function `SetFormattedText'
Interface\AddOns\oUF_Mu\core\layout.lua:242: in function
 <Interface\AddOns\oUF_Mu\core\layout.lua:241>
(tail call): ?
(tail call): ?
(tail call): ?
Interface\AddOns\oUF\elements\altpowerbar.lua:143: in function `func'
Interface\AddOns\oUF\events.lua:48: in function <Interface\AddOns\oUF\events.lua:46>
(tail call): ?

Locals: (*temporary) = <unnamed> {
 0 = <userdata>
}
(*temporary) = "%s: %i"
(*temporary) = false
(*temporary) = 25
(*temporary) = "string expected, got boolean"

can anyone please explain whats wrong with the formatting and how to fix it?

shouldve pasted the actual code from the core file


Code:

if cfg.altpowerbar then                -- alt power bar skinning
                        local altpower = CreateFrame('StatusBar', nil, UIParent)
                        altpower:SetStatusBarTexture(cfg.powertex)
                        altpower:SetStatusBarTexture(0.6, 0.6, 0.6)
                        altpower:SetSize(160, 4)
                        altpower:SetPoint('TOP', 0, -136)
                       
                        local bg = altpower:CreateTexture(nil, 'BACKGROUND')
                        bg:SetAllPoints(altpower)
                        bg:SetTexture(0.1, 0.1, 0.1, 0.75)
                        altpower.bg = bg
                       
                        local value = altpower:CreateFontString(nil, 'OVERLAY')
                        value:SetFont(cfg.font, cfg.fontsize, cfg.fontflag)
                        value:SetPoint('TOP', altpower, 'BOTTOM', 0, -4)
                        altpower.value = value
                       
                        altpower.border = mu.createBorder(altpower)
                        altpower.PostUpdate = function(Bar, min, cur, max)
                        Bar.value:SetFormattedText('%s%s', Bar.powerName, cur)
                        end
                       
                        self.AltPowerBar = altpower
                end


Fizzlemizz 09-25-15 02:24 PM

The second parameter being passed to SetFormattedText at line 242 in the file Interface\AddOns\oUF_Mu\core\layout.lua is a boolean (true/false) insted of text.

kawe 09-26-15 03:04 AM

yes, but how is it that this worked before? (5.x & prev)

and how should i format it then? %s%s? %d %i? it only shows the current alt.power value

fixed, seems that %s%s did the trick for correct display, thx for reply

Aanson 09-27-15 10:04 PM

Just wanted to quickly point out that the text might look a little better with a space or two between the values and some brackets:

Code:

Bar.value:SetFormattedText('%s (%s)', Bar.powerName, cur)
Also, if you'd like to ensure that this function is only called when the value of 'cur' is a string, replace the call with this:

Code:

if (type(cur) == 'string') then
  Bar.value:SetFormattedText('%s (%s)', Bar.powerName, cur);
end


kawe 09-28-15 05:38 AM

alright, that is indeed better. :)

my thanks

SDPhantom 09-29-15 07:20 PM

Quote:

Originally Posted by Aanson (Post 311200)
Also, if you'd like to ensure that this function is only called when the value of 'cur' is a string, replace the call with this:

Code:

if (type(cur) == 'string') then
  Bar.value:SetFormattedText('%s (%s)', Bar.powerName, cur);
end


This only stops the error from occurring, but doesn't solve the underlying problem. A better question is why does the entry have false stored in it rather than a usable value? This is an example of a logic error rather than a syntax one since something is corrupting data and causing other code to raise errors.

Phanx 09-29-15 11:53 PM

Assuming the error is ocurring in this code:
Code:

altpower.PostUpdate = function(Bar, min, cur, max)
        Bar.value:SetFormattedText('%s%s', Bar.powerName, cur)
end

.... then your "solution" just makes this function do nothing, since the cur value is always a number (but you're checking to see if it's a string) and isn't addressing the problem anyway, since your error indicates that Bar.powerName is the boolean, not cur.

The underlying problem is that the return values from UnitAlternatePowerInfo have apparently changed since that part of oUF was last updated. According to Blizzard code, the current return values are:

Code:

barType, minPower, startInset, endInset, smooth, hideFromOthers, showOnRaid, opaqueSpark, opaqueFlash, anchorTop, powerName, powerTooltip, costString, barID = UnitAlternatePowerInfo(unit)
...but oUF is assuming something in the middle isn't there, and assigning to "powerName" what is actually the "anchorTop" value by Blizzard's naming. I've opened a pull request on GitHub, but in the meantime, you can apply the fix by opening oUF/elements/altpowerbar.lua and adding another underscore in the list of values from UnitAlternatePowerInfo, like so:

Code:

        local barType, min, _, _, _, _, _, _, _, _, powerName, powerTooltip = UnitAlternatePowerInfo(unit)

kawe 09-30-15 08:47 AM

well thx for the explanation, my solution was that the error disappeared en the bar skinning worked again :P

before i go into depths with lua and/or oUF i should put more effort into programming and learning lua, which, to this day has not happend :D :rolleyes:

so i am mostly editing and trying to "fix" issues with some addons through my basic knowledge and of course wow interface forums ;)

but oUF_Mu hasn't been updated since 5.4 and some important elements are not working properly.

thx anyway for reply's, learned a little bit more :)

Phanx 10-02-15 05:38 AM

Quote:

Originally Posted by kawe (Post 311244)
before i go into depths with lua and/or oUF i should put more effort into programming and learning lua, which, to this day has not happend

Writing Lua *is* programming. There's no need to go read a textbook or take a class, unless you're really bad at self-teaching. Just keep doing what you're doing -- what you're doing *is* putting effort into learning. Read code, figure out how it works, figure out how to change it. If you don't understand how something works, you can ask, or you can just try something and see what happens.

Remember that you're working with a UI addon for a video game, not the nuclear football. It's okay to make mistakes, and you'll (probably) learn more by trying something and screwing up than you will be having someone else tell you what to do. Of course there's nothing wrong with asking questions, but don't be afraid to experiment either.


All times are GMT -6. The time now is 02:37 AM.

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