Thread Tools Display Modes
05/31/14, 07:19 PM   #1
lyravega
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 93
Callbacks - What am I doing wrong?

I made a little plug-in for FTC. Atropos contacted me, and gave me some hints, and mentioned me about callbacks. When FTC is ready, it fires a callback called "FTC_Ready". Now, I am trying to use this in my add-on, trying to integrate my plug-in settings to his add-on's settings menu.

But it doesn't work. So my question is, are the menus created before the callbacks are called/registered? Can some prehook help me out with this?

It isn't of utmost importance, I just wanted to make use of this simple callback while creating my submenu. I can use something else (like, a simple "if FTC then") and delay my submenu creation with another simple thing (so that it won't throw any errors and correctly place itself).
  Reply With Quote
05/31/14, 07:39 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
So... Since you didn't say, I'm going to have to ask. Did you register for the callback and wait for that to fire before doing what you want to do? Or is it not the correct time when the callback fires?

(I'm pretty sure you've seen this, but just putting here for reference
http://wiki.esoui.com/AddOn_Quick_Qu...s.22_in_Lua.3F
  Reply With Quote
05/31/14, 08:16 PM   #3
lyravega
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 93
Yup yup, I register the callback. FTC fires it. Via my register, I tested a simple thing, like setting a boolean (FTC_is_loaded) to true from false. When FTC is enabled, it returns true, otherwise false, so it is working as far as I can tell.

However, if I try running my menu create function when this callback is registered, it doesn't do anything. I thought I was doing something wrong, so I tried several combinations (as in, using a boolean and creating the menu if it is true - which is essentially the same thing).

That's why I asked this question; it looks like callbacks are fired/registered after all initializations and stuff, like they are deposited at somewhere while stuff are loading, then they fire (similar to ADD_ON_LOADED vs PLAYER_ACTIVATED in a way).

edit: Hmm, thinking of ADD_ON_LOADED vs PLAYER_ACTIVATED, one thing I never tested is, firing the callback at the beginning for example. I was firing it on ADD_ON_LOADED, will try before it is loaded :P But this EU maintenance thingy... jesus christ

edit2: Nah, thinking more about this, due to load order, when one add-ons fires this event, other might not register it.

edit3: Naaaaaaaaah, if that was the case, my simple callback function wouldn't set the boolean to true. Seems like callbacks are fired after register phase is over; meaning all add-ons are loaded. Guess I'll just create a global at the beginning, and make use of "OptionalDependsOn" to load the add-on before, so I can add more on top of it.

Last edited by lyravega : 05/31/14 at 08:28 PM.
  Reply With Quote
06/01/14, 12:20 AM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
You don't fire the callback. FTC does. All you do is register for it and listen for when it happens. When it fires, your registered function will run. THAT is where you should be putting your code.

FTC code:
Lua Code:
  1. CALLBACK_MANAGER:FireCallbacks("FTC_Ready")

Your code:
Lua Code:
  1. local function CreateSubmenu()
  2.      --do stuff
  3. end
  4. CALLBACK_MANAGER:RegisterCallback("FTC_Ready", CreateSubmenu)
  Reply With Quote
06/01/14, 03:05 AM   #5
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Just FYI:
FTC fires callback "FTC_Ready" in function registered to the event EVENT_ADD_ON_LOADED. If your addon is loaded after FTC, your function registered to the callback will never be called. So unless you edit FoundryTacticalCombat.txt and add (optional) dependency on your addon, this will never work correctly.

EDIT:
This is a wrong answer, I didn't think of registering the callback from the main chunk of your lua file. Code in main chunk is executed before EVENT_ADD_ON_LOADED, so callback will work. See Seerah's answer below.

Last edited by Garkin : 06/11/14 at 03:57 PM. Reason: Corrected
  Reply With Quote
06/01/14, 03:33 AM   #6
lyravega
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 93
Hmm, I think I understand.

Well, "if FTC then" works for me, so I guess I'll be OK for a while. Expecting that someone with 20+ add-ons will report a bug though.
  Reply With Quote
06/01/14, 08:28 AM   #7
lyravega
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 93
Yeah, it makes sense now. When one fires, the other hasn't even been loaded. Other one needs to register first, so it has to load before but I cannot to that. What I can do is though, that simple if-check (if FTC then), and making sure FTC is loaded before. Cannot use callbacks there.
  Reply With Quote
06/01/14, 08:05 PM   #8
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
Just put your registration in the main chunk of your file. (Don't bother putting it in a function.)
  Reply With Quote
06/02/14, 03:23 AM   #9
zgrssd
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 280
Originally Posted by lyravega View Post
Yeah, it makes sense now. When one fires, the other hasn't even been loaded. Other one needs to register first, so it has to load before but I cannot to that. What I can do is though, that simple if-check (if FTC then), and making sure FTC is loaded before. Cannot use callbacks there.
If you want to be certain another addon is loaded before yours (because you depend on it), add it to the "DependsOn"* entry in the manifest.
If the dependency is a optional one (if it is there you would prefer to go second, but if not you still can work) make it a Optional Dependency* in your manifest. I use this in Unified Chat Tabs to make certain local copies of BugEater and LibAddonMenu are loaded before my addon. BugEater because without Pre-Init debug message (like autoapply) have no chance of appearing. LAM because if there is a local copy it is propably more up to date then the version I have embedded (libStub entries in LAM files do the hard work here).

*See manifest help for proper syntax

For most purposes you can think of of the .lua files of your Addon as the constructor of your addon. The only non-function thing is that local scale variables defiend outside of functions persist after the constructor has been called. You can even cancel them via a conditional return (used for libs that use LibStub)
The loaded event is fired after all constrctors have been run already.
  Reply With Quote
06/02/14, 04:22 AM   #10
lyravega
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 93
Originally Posted by zgrssd View Post
*snip*
Again, I tried all DependsOn, OptionalDependsOn, and stuff. My problem is not those. My problem is my add-on having to be loaded after another, but yet catch a callback that it fires, which is kinda impossible :P So, no callbacks for me, rather a simple if-check.
  Reply With Quote
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

ESOUI » Developer Discussions » General Authoring Discussion » Callbacks - What am I doing wrong?


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