Thread Tools Display Modes
04-06-11, 10:09 AM   #1
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 793
About ADDON_LOADED and VARIABLES_LOADED events

The description of ADDON_LOADED:
Fires when an addon and its saved variables are loaded. Fires once for each addon (i.e. an addon loaded early in sequence will see ADDON_LOADED events for all addons loaded later).

The description of VARIABLES_LOADED:
Fires when non-addon-specific saved variables are loaded. Addons should generally use ADDON_LOADED to determine whether their saved variables have loaded.

Now here is an example of my own experience.
I use ADDON_LOADED to detect when my addon and the variables are loaded, for all my addons. Now the interesting part is that at some point in some addon I actually used the variables after ADDON_LOADED and they were not yet populated, so I played a bit and added VARIABLES_LOADED so after addon loaded I would also register VARIABLES_LOADED and after the variables one, THEN my variable was truly loaded.

It was weird, anyone else had such experience? :/
  Reply With Quote
04-06-11, 04:58 PM   #2
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
Yes and no. I've not yet found the pattern for what is the right way to describe what happens sometimes during the loading process.
But I think its safe to say there is something not always the way we expect it

I get the best results when I check for the event that comes first addon_loaded or player_login. I know that normally player_login cant occur before addon_loaded still this construct helps me to not run in the problem you describe. PLAYER_ENTERING_WORLD is the event I found the most reliable point for data validity. But I feel bad when I use it instead of addon_loaded for initializing my addons

lua Code:
  1. local name, addon = ...
  2. local f = CreateFrame("Frame")
  3. local login = true
  4.  
  5. local function onevent(self, event, arg1, ...)
  6.     if(login and ((event == "ADDON_LOADED" and name == arg1) or (event == "PLAYER_LOGIN"))) then
  7.         login = nil
  8.         f:UnregisterEvent("ADDON_LOADED")
  9.         f:UnregisterEvent("PLAYER_LOGIN")
  10.         init()
  11.     end
  12. end
  13.  
  14. f:RegisterEvent("ADDON_LOADED")
  15. f:RegisterEvent("PLAYER_LOGIN")
  16. f:SetScript("OnEvent", onevent)

Edit:

btw variables loaded:
Until 3.0, VARIABLES_LOADED used to fire upon completion of the addon loading process; since 3.0, it is fired in response to CVars, Keybindings and other associated "Blizzard" variables being loaded, and may therefore be delayed until after PLAYER_ENTERING_WORLD. The event may still be useful to override positioning data stored in layout-cache.txt
http://www.wowpedia.org/AddOn_loading_process
__________________
The cataclysm broke the world ... and the pandas could not fix it!

Last edited by Rilgamon : 04-06-11 at 05:01 PM.
  Reply With Quote
04-07-11, 06:39 PM   #3
Xinhuan
A Chromatic Dragonspawn
 
Xinhuan's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 174
When ADDON_LOADED is fired, the addon it is fired for (in arg1) has loaded its own savedvariables.

Note that while loading your addon, if your addon causes a 2nd addon to be loaded using LoadAddOn() or otherwise, the 2nd addon would have its own ADDON_LOADED fire before yours and this can cause problems if your code didn't check arg1 == "myaddon".
__________________
Author of Postal, Omen3, GemHelper, BankItems, WoWEquip, GatherMate, GatherMate2, Routes and Cartographer_Routes
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » About ADDON_LOADED and VARIABLES_LOADED events


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