View Single Post
04/08/14, 03:25 PM   #9
Dio
 
Dio's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 29
Originally Posted by Brainling View Post
Yeah, I'll unregister it after the first call. I don't think I need it after that. Everything else will be a spot update triggered by another more granular event. I'm using EVENT_PLAYER_ACTIVATED to make sure my add-ons character specific environment is initialized and ready to go.
I suppose a real fail-safe way of doing it, if it's ever possible for the EVENT_ADD_ON_LOADED to happen *after* EVENT_PLAYER_ACTIVATED, is something like this:

Code:
EVENT_MANAGER:RegisterForEvent(Clarity.name, EVENT_ADD_ON_LOADED, function(event, name)
	if name == Clarity.name then
		EVENT_MANAGER:UnregisterForEvent(Clarity.name, event)
		Clarity.addOnLoaded = true

		if Clarity.playerLoaded then
			Clarity:Init()
		end
	end
end)

EVENT_MANAGER:RegisterForEvent(Clarity.name, EVENT_PLAYER_ACTIVATED, function()
	EVENT_MANAGER:UnregisterForEvent(Clarity.name, event)
	Clarity.playerLoaded = true

	if Clarity.addOnLoaded then
		Clarity:Init()
	end
end)
Then you have your addon's "init" method called only once whether EVENT_PLAYER_ACTIVATED or EVENT_ADD_ON_LOADED happens last. Again, I have no idea if that's actually possible.

Edit - I'm not going to bother with the fail-safe, but if weird stuff happens I'll fall back to the above code.

Last edited by Dio : 04/08/14 at 03:32 PM.
  Reply With Quote