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). |
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 |
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. |
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:
Your code: Lua Code:
|
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. |
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. |
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.
|
Just put your registration in the main chunk of your file. (Don't bother putting it in a function.)
|
Quote:
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. |
Quote:
|
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:
Lua Code:
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:
/edit: or even this: Lua Code:
|
All times are GMT -6. The time now is 02:46 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI