Thread Tools Display Modes
11-12-08, 11:23 AM   #21
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
The following worked perfectly for me

Code:
function pMinimap:ADDON_LOADED(event)
	pMinimapDB = pMinimapDB or {}
	for k,v in pairs(defaults) do
		if(type(pMinimapDB[k]) == 'nil') then
			pMinimapDB[k] = v
		end
	end

	self:UnregisterEvent(event)

	-- rest of the addon here

end
  Reply With Quote
11-12-08, 11:51 AM   #22
Slakah
A Molten Giant
 
Slakah's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 863
Originally Posted by p3lim View Post
The following worked perfectly for me

Code:
function pMinimap:ADDON_LOADED(event)
    pMinimapDB = pMinimapDB or {}
    for k,v in pairs(defaults) do
        if(type(pMinimapDB[k]) == 'nil') then
            pMinimapDB[k] = v
        end
    end

    self:UnregisterEvent(event)

    -- rest of the addon here

end
yup that would work.

Just a quick note though pMinimap:ADDON_LOADED will be called multiple times even though you've unregistered the event, check the addonarg matches your own addonname before doing anything.
  Reply With Quote
11-12-08, 12:01 PM   #23
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
Originally Posted by Slakah View Post
yup that would work.

Just a quick note though pMinimap:ADDON_LOADED will be called multiple times even though you've unregistered the event, check the addonarg matches your own addonname before doing anything.
Tested it with a simple print inside the function, only ran once
  Reply With Quote
11-12-08, 05:22 PM   #24
slizen
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 15
Originally Posted by p3lim View Post
Tested it with a simple print inside the function, only ran once
Yes, it runs once when the first addon loads, which might or might more likely not be pMinimap. It works fine though unless you need to do something that requires your specific addon to be loaded before doing it.
  Reply With Quote
11-12-08, 05:39 PM   #25
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Originally Posted by slizen View Post
Yes, it runs once when the first addon loads, which might or might more likely not be pMinimap. It works fine though unless you need to do something that requires your specific addon to be loaded before doing it.
which of course you do, in this case.

just to clarify...ADDON_LOADED fires for all frames that have it registered every time any addon loads, which means it almost certainly will fire numerous times -- and your handler for it will execute numerous times -- before your own saved variables have been loaded
  Reply With Quote
11-12-08, 05:43 PM   #26
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Yes, when ADDON_LOADED or VARIABLES_LOADED fires, you should check to make sure that it was for your addon/variables. I, personally, prefer to use the PLAYER_LOGIN event. It will only fire once, and pretty much everything should be loaded and ready by then.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
11-13-08, 08:36 AM   #27
slizen
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 15
I'm pretty sure all enabled addon's saved variables are ready by the time the first ADDON_LOADED fires, since p3lim says it works even without a addon name check.
  Reply With Quote
11-13-08, 08:41 AM   #28
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Originally Posted by slizen View Post
I'm pretty sure all enabled addon's saved variables are ready by the time the first ADDON_LOADED fires, since p3lim says it works even without a addon name check.
it's possible that they changed how the event works, but i doubt it.
VARIABLES_LOADED is the event that fires when all addons have had their saved variables loaded. ADDON_LOADED fires after each successive addon's variables are loaded (and when LOD addons load). thus, for VARIABLES_LOADED, you don't need to do a check; for ADDON_LOADED, you should, assuming that you actually need your variables to have been loaded.
  Reply With Quote
11-13-08, 09:18 AM   #29
Slakah
A Molten Giant
 
Slakah's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 863
Originally Posted by slizen View Post
I'm pretty sure all enabled addon's saved variables are ready by the time the first ADDON_LOADED fires, since p3lim says it works even without a addon name check.
The addonname check is to prevent the "OnEvent" function being called more than once.
  Reply With Quote
11-13-08, 10:17 AM   #30
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Originally Posted by Akryn View Post
it's possible that they changed how the event works, but i doubt it.
VARIABLES_LOADED is the event that fires when all addons have had their saved variables loaded. ADDON_LOADED fires after each successive addon's variables are loaded (and when LOD addons load). thus, for VARIABLES_LOADED, you don't need to do a check; for ADDON_LOADED, you should, assuming that you actually need your variables to have been loaded.
Ah, yes, that's right.
http://www.wowwiki.com/Events_that_f...oading_process
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
11-13-08, 12:33 PM   #31
slizen
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 15
Originally Posted by Slakah View Post
The addonname check is to prevent the "OnEvent" function being called more than once.
Yes, but if it's the case that all addons's saved variables are loaded when the first ADDON_LOADED fires you can just skip the addon name check and unregister ADDON_LOADED right after it has fired for the first time.
  Reply With Quote
11-13-08, 01:36 PM   #32
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
But that's not how the event works, as documented by the wowwiki link I posted above.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
11-13-08, 03:37 PM   #33
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
And if you want to do it that way, you can just use VARIABLES_LOADED, and not worry about name checks or unregistering the event. VARIABLES_LOADED, or PLAYER_LOGIN or PLAYER_ENTERING_WORLD (but don't use that one) or something, is actually better than ADDON_LOADED unless your addon is LOD, imo.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Better Saved Variables Tutorial?

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