Quantcast
Totem Tag - help needed - WoWInterface
 
Thread Tools Display Modes
12-11-13, 01:01 PM   #1
Pyrates
A Cliff Giant
 
Pyrates's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 77
Totem Tag - help needed

Hi all!

Can someone tell me what's wrong with the following tag?

Code:
oUF.Tags.Methods["shrooms"] = function(u)
	local count = 0
	for i=1,3 do
		local _,_,_,dur = GetTotemInfo(i)
		if dur > 0 then
			count = count + 1
		end
	end

	local color = cfg.colors.power.CP[2*count-1]

	if count == 0 then
		return("")
	else
		return ("|cFF%.2x%.2x%.2x%s|r"):format(color[1] * 255, color[2] * 255, color[3] * 255, count)
	end
end
oUF.Tags.Events['shrooms'] = 'PLAYER_TOTEM_UPDATE'
oUF.Tags.SharedEvents["PLAYER_TOTEM_UPDATE"] = true
I've confirmed the the fontstring it's tagged on is there and shows up if I set a text, the event fires properly... I'm at a loss. Thanks for any help!
__________________
" ... and the Vogon will do things to you that you wish you'd never been born, or, if you're a clearer minded thinker, that the Vogon had never been born."
  Reply With Quote
12-11-13, 04:36 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Do you have Lua errors turned on or BugSack installed?
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Donít message me about addon bugs or programming questions.
  Reply With Quote
12-12-13, 12:30 PM   #3
Pyrates
A Cliff Giant
 
Pyrates's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 77
Yes I do. None whatsoever.

Btw, I just came back after a 2y break, and I remember you (esp. for being helpfull). Nice to see you around still
__________________
" ... and the Vogon will do things to you that you wish you'd never been born, or, if you're a clearer minded thinker, that the Vogon had never been born."
  Reply With Quote
12-12-13, 06:46 PM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Actually on second glance, I think this is your problem:

Code:
("|cFF%.2x%.2x%.2x%s|r"):format(color[1] * 255, color[2] * 255, color[3] * 255, count)
%.2x does not guarantee a 2-digit result; it guarantees a result with no more than 2 digits after the decimal point. You want to use %02x instead.

For example, format("%02f", 10 / 3) == "03.33333333333333333", but format("%.2f", 10 / 3) == "3.33". So, if your color values are 1, 0.5, and 0 then you're converting them into ff (ok), 99 (ok) and 0 (not ok) to end up with "|cffff990<<count>>|r" which isn't a valid color code. Technically you are producing a valid color code when combined with your count, since 1, 2, and 3 are valid hexadecimal values -- "|cffff9903|r" -- but then you don't have any text to display.

Also, ("text"):format(...) is the slowest possible method of formatting a string. Use format("text", ...) instead:

Code:
return format("|cff%02x%02x%02x%s|r", color[1] * 255, color[2] * 255, color[3] * 255, count)
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Donít message me about addon bugs or programming questions.

Last edited by Phanx : 12-12-13 at 06:48 PM.
  Reply With Quote
12-13-13, 12:21 PM   #5
Pyrates
A Cliff Giant
 
Pyrates's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 77
Thanks for your suggestions. I tried it, but to no avail I also inserted a print statement, and it seems clear to me the function is never called. I did confirm PLAYER_TOTEM_UPDATE fires when I plant a mushroom... might have something to do with the unitless events, but I have no idea how to check for that.

I did run this script ingame:
Code:
local event = 'PLAYER_TOTEM_UPDATE'
for i = 1, select( "#", GetFramesRegisteredForEvent(event)) do
 local frame = select(i,GetFramesRegisteredForEvent(event))
 print(frame:GetName())
local func1 = frame:GetScript("OnEvent")
print(func1)
end
It printed "TotemFrame" and a function number... seems reasonable enough, but I don't know where to go from here. I tried running "func1("PLAYER_TOTEM_UPDATE",1)", but that didn't do anything...

(e) I just remembered, there's another tag that's not working. I didn't want to ask 2 questions at once, but maybe they're connected? The other tag is

Code:
oUF.Tags.Events['BossBars:health'] = oUF.Tags.Events["curhp"] .. " " .. oUF.Tags.Events["maxhp"]
oUF.Tags.Methods['BossBars:health'] = function(unit)
		local m = UnitHealthMax(unit)
		if(m == 0) then
			return 0
		else
			return math.floor(UnitHealth(unit)/m*100+.5)
		end
end
It's "somewhat" working in that it shows HP percent, but it only updates when I change target. Seems some events don't reach their functions? Strange, the other tags seem to work just fine (and the healthbar of that unit works nicely as well).
__________________
" ... and the Vogon will do things to you that you wish you'd never been born, or, if you're a clearer minded thinker, that the Vogon had never been born."

Last edited by Pyrates : 12-13-13 at 02:28 PM.
  Reply With Quote
12-13-13, 06:17 PM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Well here is an example tag from my own layout that is definitely working with a "unitless" event:

Code:
oUF.Tags.Events["restingicon"] = "PLAYER_UPDATE_RESTING"
oUF.Tags.SharedEvents["PLAYER_UPDATE_RESTING"] = true
oUF.Tags.Methods["restingicon"] = function(unit)
	if unit == "player" and IsResting() then
		return [[|TInterface\CharacterFrame\UI-StateIcon:0:0:0:-6:64:64:28:6:6:28|t]]
	end
end
Based on that, here is how I would write a mushroom counter tag (with your coloring):

Code:
oUF.Tags.Events["mushrooms"] = "PLAYER_TOTEM_UPDATE"
oUF.Tags.SharedEvents["PLAYER_TOTEM_UPDATE"] = true
oUF.Tags.Methods["mushrooms"] = function(unit)
	if unit == "player" then
		local count = 0
		for i = 1, MAX_TOTEMS do
			local _, _, _, duration = GetTotemInfo(i)
			if duration > 0 then
				count = count + 1
			end
		end
		print("UPDATE TAG: mushrooms", count)
		if count > 0 then
			local color = cfg.colors.power.CP[2 * count - 1]
			return format("|cff%02x%02x%02x%d|r", color[1] * 255, color[2] * 255, color[3] * 255, count)
		end
	end
end
I don't have a druid to test that on, though.

For your health tag, I suspect the problem is the way you are listing events. Rather than concatenating the events from other tags (which may or may not be defined yet when your code runs) just write out the events; there are only two of them. Also, you don't need to explicitly return an empty string or a zero if there's no value; just don't return anything, and the fontstring will be emptied.

Code:
oUF.Tags.Events["BossBars:health"] = "UNIT_HEALTH UNIT_MAXHEALTH"
oUF.Tags.Methods["BossBars:health"] = function(unit)
	local m = UnitHealthMax(unit)
	if m > 0 then
		return floor(UnitHealth(unit) / m * 100 + 0.5)
	end
end
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Donít message me about addon bugs or programming questions.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Totem Tag - help needed

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