Go to Page... |
Thread Tools | Display Modes |
03/11/15, 08:09 PM | #1 |
Important, Simple, Easily Overlooked Load Error
I've been meaning to remember to start a discussion about this since at least November. Other things intrude, as they so often do.
I made a discovery when I was playing around with a new addon that is very counter-intuitive and probably should go into the wiki tutorial. Here goes: It does not matter what ADDON_NAME is passed to your OnAddonLoaded function from the ON_ADDON_LOADED event register. The only ADDON_NAME the event will pass to your OnAddonLoaded function is the Name of the Addon Folder It's so very basic, but it'll raise hell for anyone who doesn't know about it; I know I've seen the KillCounter addon displaying all loaded addon names (I comment that line out in my copy) like I did to figure this out. Simply put, if these names don't match, your addon won't load if you have a line like this in your OnAddonLoad function: Code:
if ADDON_NAME == "TheAddonNamePassedtothisFunction" then Code:
d(addonName) Stupid, I know, but I've spoken to a few developers who had to change their pants after I told them. |
|
03/11/15, 09:01 PM | #2 | |
|
Also the manifest (txt file) must match the folder name or it wont run any of your code. I'm guessing what you meant was that it does not matter what name you pass to "register" the event: Lua Code:
But the addonName passed to your OnAddonLoaded function does matter. That is how you know when your addon or others are loaded. If your addon is not fully loaded & you start trying to call functions your going to have problems. Same if your trying to use/access something from another addon. The OnAddonLoaded function tells us when the code in that addon is available. Lua Code:
For example what if only the first code file of your addon was loaded but in it you started calling functions defined in another code file, before it got loaded? The OnAddonLoaded event/function is how we know when the addon is loaded, all of it. Last edited by circonian : 03/11/15 at 09:06 PM. |
|
03/11/15, 10:32 PM | #3 |
|
There's nothing stupid about it. Surprising for the unwary, perhaps, but it totally makes sense.
I was going to blame the wiki for your confusion, but after glancing at a few pages, no. For example nowhere on AddOn Quick Questions or EVENT_ADD_ON_LOADED it states that the two arguments you're talking about are interconnected. They aren't, they're completely different things. EVENT_MANAGER:RegisterForEvent(tag, event, handler) The first argument (after self) should be a string uniquely identifying the listener. I call that argument tag, others call it namespace. The wiki pages use variants of "YourAddonName" as its value, because it's a natural namespace. You can't say it doesn't matter. If we all start using "Timbuktu", each event will only be delivered to one add-on -- the one that registers it first. You absolutely have to keep that unique. EVENT_ADD_ON_LOADED(eventCode, addonName) The second argument is an actual add-on name. It has nothing to do with the identity of the listener. Everyone who registered for the event receives the same list of add-on names. |
03/12/15, 08:23 PM | #4 | ||
|
|||
ESOUI » Developer Discussions » General Authoring Discussion » Important, Simple, Easily Overlooked Load Error |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|