Originally Posted by jostor
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:
function addon:ADDON_LOADED(arg1)
if arg1 ~= addon.name then return end
-- do stuff here
if IsLoggedIn() then
self:PLAYER_LOGIN()
else
self:RegisterEvent('PLAYER_LOGIN')
end
end
function addon:PLAYER_LOGIN()
-- do stuff here
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:
local OnEvent = function(frame, event, ...)
if event == 'ADDON_LOADED' and ... == addonName then
-- do stuff
if IsLoggedIn() then
OnEvent(frame, 'PLAYER_LOGIN')
else
frame:RegisterEvent'PLAYER_LOGIN'
end
elseif bla then
-- Bla
end
end
frame:RegisterEvent'ADDON_LOADED'