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:
local function CheckTalents()
local _, talents = GetTalentTabInfo(GetPrimaryTalentTree(false, false, GetActiveTalentGroup()))
return talents
end
function addon:event()
text:SetText(CheckTalents())
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.