Reply
Thread Tools Display Modes
Unread 07-10-10, 11:32 PM   #1
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 311
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?

Last edited by suicidalkatt : 07-11-10 at 12:11 AM.
suicidalkatt is online now   Reply With Quote
Unread 07-11-10, 01:37 AM   #2
Taryble
A Molten Giant
 
Taryble's Avatar
Join Date: Jan 2009
Posts: 811
You can use [color_ifnot_mp99] to reverse the mp99 tag.
__________________
-- Taryble
Taryble is offline   Reply With Quote
Unread 07-11-10, 02:36 AM   #3
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 311
Originally Posted by Taryble View Post
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?
suicidalkatt is online now   Reply With Quote
Unread 07-11-10, 11:20 AM   #4
Taryble
A Molten Giant
 
Taryble's Avatar
Join Date: Jan 2009
Posts: 811
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_mp99ercmp][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).
__________________
-- Taryble

Last edited by Taryble : 07-11-10 at 11:24 AM. Reason: spelling and ifnot info
Taryble is offline   Reply With Quote
Unread 07-11-10, 11:46 AM   #5
ChaosInc
Curse staff
 
ChaosInc's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 670
In lua, single or double quotes are one in the same; You can use either.
__________________
Originally posted by Mirrikat45
so says the 1/2 million downloads per week.......
Impossible statistics = FAIL!! But don't point this out, or your post will be deleted!
ChaosInc is offline   Reply With Quote
Unread 07-12-10, 04:32 AM   #6
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,057
Originally Posted by ChaosInc View Post
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.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of Revelation, Spamalyzer, TravelAgent, Volumizer, and many other AddOns.
Torhal is offline   Reply With Quote
Unread 07-12-10, 08:58 AM   #7
Taryble
A Molten Giant
 
Taryble's Avatar
Join Date: Jan 2009
Posts: 811
Good information to know. :-)
__________________
-- Taryble
Taryble is offline   Reply With Quote
Unread 07-12-10, 12:01 PM   #8
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 9,629
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."
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

Seerah is offline   Reply With Quote
Unread 07-13-10, 02:43 AM   #9
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 311
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.
suicidalkatt is online now   Reply With Quote
Reply

Go BackWoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Stuf Custom String - Lua

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