View Single Post
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