View Single Post
06/02/14, 06:56 PM   #11
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
Again, register for your callback in the main chunk (top level) of the addon. You can still wait for whenever you want to actually do everything else in your addon.
Lua Code:
  1. local function AddonInitialization()
  2.      --do stuff that I
  3.      --have to wait until
  4.      --now to do
  5. end
  6.  
  7. EVENT_MANAGER:RegisterEvent(EVENT_PLAYER_READY, AddonInitialization)
In the above example, the last line is in the main chunk of your addon - it is not wrapped within a function, or an if-then block, or a do-end, block, etc. You can do anything you want in the main chunk of your addon, so long as it doesn't depend on other things. In the ESOutpost addon, I create the *entire GUI* in the main chunk of the GUI.lua file. The only reason to do this...
Lua Code:
  1. local function MyFunc()
  2.      --do stuff
  3. end
  4. MyFunc()
...is if you want to be able to call that function again later, for example. (Or if you want to isolate something in that scope, but you could also enclose that in a do-end block...)

So, again... In the main chunk of your addon, register for the "FTC_Ready" callback. It can go anywhere in the file, so long as it's after the function you want it to call was defined.

Lua Code:
  1. local function FCTReadyCallback()
  2.      --do stuff now that FTC is done
  3. end
  4.  
  5. CALLBACK_MANAGER:RegisterCallback("FTC_Ready", FCTReadyCallback)
  6.  
  7. local function AddonInitialization()
  8.      --do stuff that I
  9.      --have to wait until
  10.      --now to do
  11. end
  12.  
  13. EVENT_MANAGER:RegisterEvent(EVENT_PLAYER_READY, AddonInitialization)


/edit: or even this:
Lua Code:
  1. local function CreateSubmenu()
  2.      --do stuff now that FTC is done
  3. end
  4.  
  5. local function AddonInitialization()
  6.      --do other stuff that I
  7.      --have to wait until
  8.      --now to do
  9.  
  10.      CreateSubmenu()
  11. end
  12.  
  13. CALLBACK_MANAGER:RegisterCallback("FTC_Ready", AddonInitialization)
  Reply With Quote