Quantcast GetTalentInfo returns nil when zoning into time-walking dungeons, arena, battleground - WoWInterface
Thread Tools Display Modes
02-24-18, 05:00 PM   #1
Eungavi
A Theradrim Guardian
Join Date: Nov 2017
Posts: 64
GetTalentInfo returns nil when zoning into time-walking dungeons, arena, battleground

Hey!

So, one of my addon has a frame that listens to ACTIVE_TALENT_GROUP_CHANGED event which calls GetTalentInfo to check whether the specific talent is selected or not when its fired.

I honestly dunno why, but GetTalentInfo seems to be returning a nil value when the player zones into time-walking dungeons, arena and battleground.

Here's a code snippet:

Lua Code:
  1. local f = CreateFrame("Frame")
  2. f:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED")
  3. f:SetScript("OnEvent", function(self, event, ...)
  4.     self[event](self, ...)
  5. )
  6.  
  7. function f:ACTIVE_TALENT_GROUP_CHANGED()
  8.     local _, _, _, selected = GetTalentInfo(7, 1, 1)
  9.  
  10.     if selected then
  11.         objectA:Show()
  12.     else
  13.         objectA:Hide()
  14.     end
  15.  
  16.     _, _, _, selected = GetTalentInfo(1, 1, 1)
  17.  
  18.     if selected then
  19.         objectB:Show()
  20.         objectB:RegisterEvent("PLAYER_TARGET_CHANGED")
  21.     else
  22.         objectB:Hide()
  23.         objectB:UnregisterEvent("PLAYER_TARGET_CHANGED")
  24.     end
  25. end

Both, objectA and objectB are hidden when I enter those zones and I'll have to reload ui to see them again
(This function is the only part where it manages those objects' visibility)

What would be causing this and would there be any possible solutions?

Last edited by Eungavi : 02-24-18 at 05:06 PM.
  Reply With Quote
03-02-18, 04:16 PM   #2
aallkkaa
A Theradrim Guardian
 
aallkkaa's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2017
Posts: 63
In my rather limmited experience with WoW events, they tend to fire more often than we expect. i.e. when you don't expect them to. And sometimes they don't fire when it would be logical (at least according to our expectations) for them to. Zoneing in and out of instances are moments when this often happens.

So, if I understood correctly, you're only calling GetTalentInfo upon ACTIVE_TALENT_GROUP_CHANGED, right?
I'm guessing maybe that event is fireing in between PLAYER_LEAVING_WORLD and PLAYER_ENTERING_WORLD, making the access to talents unavailable in that period. It may be that they become available again on PLAYER_ENTERING_WORLD (and you'd expect ACTIVE_TALENT_GROUP_CHANGED to fire again but it doesn't).
I have tested nothing of the above, it's just guess-work!. But you could try this:

Lua Code:
  1. local f = CreateFrame("Frame")
  2.  
  3. local function MyUpdateTalentsHandler(self, ...)
  4.     local _, _, _, selected = GetTalentInfo(7, 1, 1)
  5.  
  6.     if selected then
  7.         objectA:Show()
  8.     else
  9.         objectA:Hide()
  10.     end
  11.  
  12.     _, _, _, selected = GetTalentInfo(1, 1, 1)
  13.  
  14.     if selected then
  15.         objectB:Show()
  16.         objectB:RegisterEvent("PLAYER_TARGET_CHANGED")
  17.     else
  18.         objectB:Hide()
  19.         objectB:UnregisterEvent("PLAYER_TARGET_CHANGED")
  20.     end
  21. end
  22.  
  23. f:ACTIVE_TALENT_GROUP_CHANGED = MyUpdateTalentsHandler
  24. f:PLAYER_ENTERING_WORLD = MyUpdateTalentsHandler
  25.  
  26. f:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED")
  27. f:RegisterEvent("PLAYER_ENTERING_WORLD")
  28. f:SetScript("OnEvent", function(self, event, ...)
  29.     self[event](self, ...)
  30. )

Last edited by aallkkaa : 03-02-18 at 04:19 PM. Reason: Fixed typo
  Reply With Quote
03-05-18, 08:44 PM   #3
Eungavi
A Theradrim Guardian
Join Date: Nov 2017
Posts: 64
@aallkkaa,

So, you are saying that it's like:

PLAYER_LEAVING_WORLD → ACTIVE_TALENT_GROUP_CHANGED → PLAYER_ENTERING_WORLD ?

Hm..........................
If so, my question is why is it not causing an issue when you join random dungeons or raids ?
  Reply With Quote
03-06-18, 12:08 AM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,616
It's probably a race condition; the two events are actually fired simultaneously, but in practice one of them has to be handled before the other since the UI is single-threaded and can only do one thing at a time. It could also be that the events are fired in a different order for different types of instances. Without being able to look at the C code that fires the events, there's no way for us to know which is the case.

Fortunately, we don't need to know -- just use aallkkaa's solution. It will run your "check talents and update frame visibility" function on both events, so it won't matter which order they fire in.
__________________
Author/maintainer of Grid, PhanxChat, oUF_Phanx, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!
  Reply With Quote
03-06-18, 02:28 AM   #5
Eungavi
A Theradrim Guardian
Join Date: Nov 2017
Posts: 64
@Phanx,

That's understandable.

For now, I'll stick with aallkkaa's solution

Thank you guys!!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » GetTalentInfo returns nil when zoning into time-walking dungeons, arena, battleground

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