Thread Tools Display Modes
06-07-13, 07:22 AM   #1
jostor
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Nov 2011
Posts: 10
GetSpecialization() doesn't return correctly right upon login - workaround?

I'm writing an addon where which frames are shown depends a bit on your talent spec, and it seems that right as you log in GetSpecialization() sometimes doesn't return a correct value, most likely because your spec and so on hasn't been loaded in yet.
I am trying to use it in the ADDON_LOADED event, and it seems to work correctly about 50% of the time when logging in, and when I just reload my UI it works more or less 100% of the time.

Is there a neat workaround for this? Is there a specific order that events are fired as you log in?
  Reply With Quote
06-07-13, 09:00 AM   #2
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
http://www.wowpedia.org/AddOn_loadin...iables_loading

Don't take this as some kind of bible, event order has changed in the past but it's relatively trustworthy.
PLAYER_LOGIN is the event you want for initializing game data most of the time.
  Reply With Quote
06-07-13, 09:27 AM   #3
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
I had the same issue with CRITERIA UPDATE firing twice when logging in, the first one was right after ADDON_LOADED, the second after PLAYER_LOGIN. GetAchievementCriteriaInfo() returned completed data on the second occurence.
  Reply With Quote
06-07-13, 09:34 AM   #4
jostor
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Nov 2011
Posts: 10
PLAYER_LOGIN seems to work better and I wasn't able to trigger the error with using that instead, so thanks for that

Is there any way that PLAYER_LOGIN could be before ADDON_LOADED in extreme situations? My code right now relies on ADDON_LOADED going first.
  Reply With Quote
06-07-13, 09:43 AM   #5
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
Originally Posted by jostor View Post
Is there any way that PLAYER_LOGIN could be before ADDON_LOADED in extreme situations? My code right now relies on ADDON_LOADED going first.
This is how I would solve it, assuming you are using a table style event handling approach:

lua Code:
  1. function addon:ADDON_LOADED(arg1)
  2.     if arg1 ~= addon.name then return end
  3.     -- do stuff here
  4.     if IsLoggedIn() then
  5.         self:PLAYER_LOGIN()
  6.     else
  7.         self:RegisterEvent('PLAYER_LOGIN')
  8.     end
  9. end
  10.  
  11. function addon:PLAYER_LOGIN()
  12.     -- do stuff here
  13. end
If you are running an if/else style event handler, just call the event handler function from the function itself, with parameters:
lua Code:
  1. local OnEvent = function(frame, event, ...)
  2.     if event == 'ADDON_LOADED' and ... == addonName then
  3.         -- do stuff
  4.         if IsLoggedIn() then
  5.             OnEvent(frame, 'PLAYER_LOGIN')
  6.         else
  7.             frame:RegisterEvent'PLAYER_LOGIN'
  8.         end
  9.     elseif bla then
  10.         -- Bla
  11.     end
  12. end
  13. frame:RegisterEvent'ADDON_LOADED'
  Reply With Quote
06-07-13, 09:09 PM   #6
jeruku
A Cobalt Mageweaver
 
jeruku's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 223
Have you tried PLAYER_ALIVE or PLAYER_ENTERING_WORLD?
__________________
"I have not failed, I simply found 10,000 ways that did not work." - Thomas Edison
  Reply With Quote
06-07-13, 11:20 PM   #7
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by jeruku View Post
Have you tried PLAYER_ALIVE or PLAYER_ENTERING_WORLD?
If you use either of those, make sure you unregister them after seeing them, as they don't just fire on login -- they also fire every time you release your spirit, accept a resurrection, or pass through a loading screen.
__________________
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
06-08-13, 11:28 AM   #8
lilsparky
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Oct 2007
Posts: 117
for cases like this where it's ambiguous what data is available when, you can set up a timer to periodically run a simple function that checks for good return results (ie, not nil) on functions you're interested in. if it makes it thru the series of checks, then it kills the timer and fires off the your actual initialization function.

i had to do this to check when profession information is available as no events seem to work 100% of the time. also makes it future proof should blizzard re-arrange event order.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » GetSpecialization() doesn't return correctly right upon login - workaround?


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