WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   GetTalentInfo returns nil when zoning into time-walking dungeons, arena, battleground (https://www.wowinterface.com/forums/showthread.php?t=56065)

Eungavi 02-24-18 05:00 PM

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 :confused:
(This function is the only part where it manages those objects' visibility)

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

aallkkaa 03-02-18 04:16 PM

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. )

Eungavi 03-05-18 08:44 PM

@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 :confused:?

Phanx 03-06-18 12:08 AM

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.

Eungavi 03-06-18 02:28 AM

@Phanx,

That's understandable.

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

Thank you guys!!


All times are GMT -6. The time now is 06:23 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI