WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   Stuf Custom String - Lua (https://www.wowinterface.com/forums/showthread.php?t=33855)

suicidalkatt 07-10-10 11:32 PM

Stuf Custom String - Lua
 
I'm trying to create a text pattern for my stuf frames that would show a percentage of mana with the added exact amounts depending on whether the amount of mana is at max or not.

For example:

100% - 20000

or

80% - 16000 / 20000

Originally I simply had this as the input:
Code:

[percmp]%[solid_if_mp99: - ][solid_if_mp99:curmp][solid_if_mp99: / ][solid_if_mp99:maxmp]
However there's no conditional I can put to only display something when the mana is at full to add the additional max mana.

So I started working on an Lua version here:
Code:

function(unit, cache, textframe)
        local mp,mpmax = UnitPower(unit),UnitPowerMax(unit)
        local pctmp = floor(100*(mp/mpmax))
        local text
        local function truncate(value)
                if value >= 1e6 then
                        return format('%.1fm', value / 1e6)
                elseif value >= 1e4 then
                        return format('%.1fk', value / 1e3)
                else
                        return value
                end
        end
        if mp == mpmax then
                text = pctmp.."%"
        else
                text = pctmp.."% "..truncate(mp).." / "..truncate(mpmax)
        end
        return text
end

This should be working as written however I get this error:
Code:

1x Stuf-3.3.006\text.lua:102: invalid option in `format'
Lines for text.lua 102:
Code:

local function AddAdvanceText(fs, a1, ...)
fs:SetFormattedText(gsub(a1 or "", "||", "|"), ...)
end


"text" does return the proper string, am I missing something?

Taryble 07-11-10 01:37 AM

You can use [color_ifnot_mp99] to reverse the mp99 tag.

suicidalkatt 07-11-10 02:36 AM

Quote:

Originally Posted by Taryble (Post 196910)
You can use [color_ifnot_mp99] to reverse the mp99 tag.

Ahh cool, didn't know there was an 'ifnot' conditional.

Any idea why my Lua setup was creating a format issue?

Taryble 07-11-10 11:20 AM

From what you posted, it looks like you used single-quotes (') where it expected double-quotes (").

The format string is supposed to be in double-quotation marks, from my understanding of Lua.
Code:

        local function truncate(value)
                if value >= 1e6 then
                        return format("%.1fm", value / 1e6)
                elseif value >= 1e4 then
                        return format("%.1fk", value / 1e3)
                else
                        return value
                end
        end

I remembered the ifnot bit from my own interface testing, where I had [solid_ifnot_mp99:maxmp][solid_if_mp99:percmp][solid_if_mp99:%][solid_if_mp99: - ][solid_if_mp99:curmp] for my mana string (and a couple of instances where I had health percentage replacing the name in ToT/Foc/ToF/Pet frames).

Sythalin 07-11-10 11:46 AM

In lua, single or double quotes are one in the same; You can use either.

Torhal 07-12-10 04:32 AM

Quote:

Originally Posted by ChaosInc (Post 196968)
In lua, single or double quotes are one in the same; You can use either.

You cannot, however, mix them. If you start a string with one, you must end it with the same.

Taryble 07-12-10 08:58 AM

Good information to know. :-)

Seerah 07-12-10 12:01 PM

This allows you to display quotes in a string. :)

print("This is 'quoted text.'")
>>This is 'quoted text.'
print('This is "quoted text."')
>>This is "quoted text."

suicidalkatt 07-13-10 02:43 AM

Regardless of which sets of " " ' ' I use, I still get the format error.

It's come down to using the ".." operator or expression extension (doesn't know the proper term) that will return a format issue.

Any single termed string or variable that is a single termed string will not give a format issue.


All times are GMT -6. The time now is 02:15 PM.

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