View Single Post
09-13-09, 03:23 PM   #1164
Wimpface
A Molten Giant
 
Wimpface's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 648
So here I am, writing yet another oUF layout based on p3lim's great work. And also, here I am, finding yet another problem writing tags for myself to use.

I'm trying to get my power text for players/pets powertype-colored and shortened to "11.2k" for example. But this just won't work the way I want it to.

(Warning for long paste, could make a pastey if wanted)
Code:
local format = string.format
local gsub = string.gsub

local colors = setmetatable({
	power = setmetatable({
		['MANA'] = {0, 144/255, 1}
	}, {__index = oUF.colors.power}),
	reaction = setmetatable({
		[2] = {1, 0, 0},
		[4] = {1, 1, 0},
		[5] = {0, 1, 0}
	}, {__index = oUF.colors.reaction}),
}, {__index = oUF.colors})

local function shortVal(value)
	if(value >= 1e6) then
		return ('%.2fm'):format(value / 1e6):gsub('%.?0+([km])$', '%1')
	elseif(value >= 1e4) then
		return ('%.1fk'):format(value / 1e3):gsub('%.?0+([km])$', '%1')
	else
		return value
	end
end

local function hex(r, g, b)
	if(type(r) == 'table') then
		if(r.r) then r, g, b = r.r, r.g, r.b else r, g, b = unpack(r) end
	end
	return ('|cff%02x%02x%02x'):format(r * 255, g * 255, b * 255)
end

oUF.Tags['[ppower]'] = function(unit)
	local _, str = UnitPowerType(unit)
	local mini = UnitPower(unit)
	return ('%s%d|r'):format(hex(colors.power[str] or {1, 1, 1}), shortVal(mini))
end
The error I get (oh and this is a lot...) is this.
Code:
Message: Interface\AddOns\oUF_Hariyama\tags.lua:40: bad argument #1 to 'format' (number expected, got string)
Time: 09/13/09 23:22:45
Count: 44660
Stack: [string "Interface\FrameXML\BasicControls.xml:<Scrip..."]:18: in function <[string "Interface\FrameXML\BasicControls.xml:<Scrip..."]:4>
[C]: ?
[C]: in function `format'
Interface\AddOns\oUF_Hariyama\tags.lua:40: in function `func'
Interface\AddOns\oUF\elements\tags.lua:402: in function `UpdateTag'
Interface\AddOns\oUF\elements\tags.lua:259: in function <Interface\AddOns\oUF\elements\tags.lua:255>

Locals: (*temporary) = "%d"
(*temporary) = ""
(*temporary) = "18.6k"
(*temporary) = 0
(*temporary) = "number expected, got string"
I just don't see what the problem is, can anyone shed some light upon this please?

- Wimpzter.
__________________
All I see is strobe lights blinding me in my hindsight.