Thread Tools Display Modes
12-10-11, 09:29 PM   #1
Wimpface
A Molten Giant
 
Wimpface's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 648
Need help with a text display for Talents

I want this to show my talent spec (i.e 'Elemental', 'Holy' etc) but it won't! So I figured I ****ed up somewhere. This leads me here!

Code:
--[[
	Based on LynStats
--]]

local addon = CreateFrame("Frame", nil, UIParent)

-- CONFIG --
-- frame
local frame_anchor = "BOTTOM"
local frame_x = 0
local frame_y = 5
-- text
local text_anchor = "BOTTOM"
local font = "Fonts\\ARIALN.TTF"
local size = 12
local classcolors = true -- true or false

if classcolors == true then
	color = CUSTOM_CLASS_COLORS[select(2, UnitClass("player"))]
else
	color = { r=0, g=0.8, b=1 } -- own textcolor
end

-- END OF CONFIG --

local text = addon:CreateFontString(nil, 'OVERLAY')
for i = 1, GetNumTalentTabs() do
	local _, talent = GetTalentTabInfo(i)
end

function addon:event()
	if (event == 'PLAYER_ENTERING_WORLD') then
		text:SetText(talent)
	elseif (event == 'ACTIVE_TALENT_GROUP_CHANGED') then
		text:SetText(talent)
	end
end

text:SetPoint(frame_anchor, frame_x, frame_y)
text:SetFont(font, size)
text:SetTextColor(color.r, color.g, color.b)
See anything wrong? I've gone over it a few times and I see nothing wrong at all.
__________________
All I see is strobe lights blinding me in my hindsight.

Last edited by Wimpface : 12-10-11 at 09:45 PM.
  Reply With Quote
12-10-11, 10:18 PM   #2
Taryble
A Molten Giant
 
Taryble's Avatar
Join Date: Jan 2009
Posts: 811
From the looks of it, your script always returns the highest talent tab's info (1 if you haven't bought dual-spec, 2 if you have).

You may want to use GetActiveTalentGroup() to find out WHICH talents are active, and then query GetTalentTabInfo() with the result from it.
__________________
-- Taryble
  Reply With Quote
12-10-11, 10:29 PM   #3
Wimpface
A Molten Giant
 
Wimpface's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 648
Originally Posted by Taryble View Post
From the looks of it, your script always returns the highest talent tab's info (1 if you haven't bought dual-spec, 2 if you have).

You may want to use GetActiveTalentGroup() to find out WHICH talents are active, and then query GetTalentTabInfo() with the result from it.
Like this?
Code:
if GetActiveTalentGroup() == 1 then
	for i = 1, GetNumTalentTabs() do
		local _, name = GetTalentTabInfo(i)
	end
	GetTalentTabInfo(1, name)
elseif GetActiveTalentGroup() == 2 then
	for i = 1, GetNumTalentTabs() do
		local _, name = GetTalentTabInfo(i)
	end
	GetTalentTabInfo(2,  name)
end
__________________
All I see is strobe lights blinding me in my hindsight.
  Reply With Quote
12-10-11, 11:02 PM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
You're using GetTalentTabInfo incorrectly. The argument it takes is a talent tab number (back when they were tabs, now it's just left to right). Also, in your original script, you were just rewriting the variable name each time through your loop. GetNumTalentTabs always returns 3 (though it will return 4 for druids in 5.0) since we have 3 talent trees.

In addition, your variable name is nil when you try to use it in GetTalentTabInfo() since you made it a variable local only to the scope of your loop. (Sidenote: when doing this, it creates a brand new local variable called name 3 times the loop runs.)

Finally, you're not actually checking your talents when your events fire. Just resetting the text. Use "PLAYER_LOGIN" rather than "PLAYER_ENTERING_WORLD". It only fires once, whereas PEW fires on each loading screen.

As Taryble said, you need to call GetActiveTalentGroup() to see if you are in your primary spec or secondary spec (if dual specced). Then you need to pass that information to GetPrimaryTalentTree() to see which tab/tree you have selected as your 'spec' (ie, 2 if you're Marksman for a hunter). Since this is the tab/tree number, you pass *that* to GetTalentTabInfo() for its name. (Sidenote: if down the road you also want to see how many points are spent in this tree, you will need to tell it which spec you are looking at. You'd probably want to save the return of GetActiveTalentGroup() to a variable at this point.)

This can be done all at once, rather than cluttering your code with variables (unless you need these variables later for something else).

I'm going to assume that what you have in the OP is not the entirety of your code, so I'll just post the relevant bits.

lua Code:
  1. local function CheckTalents()
  2.     local _, talents = GetTalentTabInfo(GetPrimaryTalentTree(false, false, GetActiveTalentGroup()))
  3.     return talents
  4. end
  5.  
  6. function addon:event()
  7.     text:SetText(CheckTalents())
  8. end


/edit: removed the local variables from the main chunk, since I make the CheckTalents() function just return the result to the :SetText() call directly.
__________________
"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


Last edited by Seerah : 12-10-11 at 11:05 PM.
  Reply With Quote
12-10-11, 11:05 PM   #5
Wimpface
A Molten Giant
 
Wimpface's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 648
Interesting. Thank you so much! <3
__________________
All I see is strobe lights blinding me in my hindsight.
  Reply With Quote
12-10-11, 11:47 PM   #6
Wimpface
A Molten Giant
 
Wimpface's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 648
A new problem arises!

It works as it's supposed to except for when you log in, I assume it's because the information isn't available when PLAYER_LOGIN fires, PLAYER_ENTERING_WORLD doesn't work either. It works after the first reload, but not before that.

Full code:
Code:
--[[
	Based on LynStats
--]]

local addon = CreateFrame("Frame", nil, UIParent)
addon:RegisterEvent('PLAYER_LOGIN')
addon:RegisterEvent('ACTIVE_TALENT_GROUP_CHANGED')

-- CONFIG --
-- frame
local frame_anchor = "BOTTOM"
local frame_x = 0
local frame_y = 5
-- text
local text_anchor = "BOTTOM"
local font = "Fonts\\ARIALN.TTF"
local size = 12
local classcolors = true -- true or false
local color = CUSTOM_CLASS_COLORS[select(2, UnitClass("player"))]

-- END OF CONFIG --
function addon:new()
	-- frame position
	self:SetPoint(frame_anchor, UIParent, frame_anchor, frame_x, frame_y)
	self:SetWidth(50)
	self:SetHeight(13)
	-- create fontstring
	text = self:CreateFontString(nil, "OVERLAY")
	-- text style
	text:SetFont(font, size)
	text:SetTextColor(color.r, color.g, color.b)
	text:SetShadowOffset(1, -1)
	
	text:SetPoint(text_anchor, self)
	
	self:RegisterEvent('PLAYER_LOGIN')
	self:RegisterEvent('ACTIVE_TALENT_GROUP_CHANGED')
	
	-- update
	self:SetScript("OnEvent", self.event)
end

local talents, _
local function CheckTalents()
    _, talents = GetTalentTabInfo(GetPrimaryTalentTree(false, false, GetActiveTalentGroup()))
    return talents
end
 
function addon:event()
	text:SetText(CheckTalents())
end

addon:new()
__________________
All I see is strobe lights blinding me in my hindsight.
  Reply With Quote
12-11-11, 12:35 AM   #7
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
See if PLAYER_TALENT_UPDATE fires when that info is ready...
__________________
"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

  Reply With Quote
12-11-11, 12:39 AM   #8
Wimpface
A Molten Giant
 
Wimpface's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 648
Originally Posted by Seerah View Post
See if PLAYER_TALENT_UPDATE fires when that info is ready...
Yup, works. Thanks again. All is well!
__________________
All I see is strobe lights blinding me in my hindsight.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Need help with a text display for Talents

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