Thread Tools Display Modes
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: 331
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.
  Reply With Quote
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
  Reply With Quote
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: 331
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?
  Reply With Quote
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
  Reply With Quote
07-11-10, 11:46 AM   #5
Sythalin
Curse staff
 
Sythalin's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 680
In lua, single or double quotes are one in the same; You can use either.
  Reply With Quote
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,196
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 NPCScan and many other AddOns.
  Reply With Quote

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


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