Thread Tools Display Modes
08-18-13, 01:44 PM   #21
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
Put the main part of your addon into a initialize function. Call this when ADDON_LOADED fires.
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
08-18-13, 08:38 PM   #22
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Caellian View Post
How can i delay my entire UI to load only once ADDON_LOADED has fired, delay a block of code is fine, but an entire UI ?
This is (one of many places) where splitting up your megalithic conglomo-mod into multiple independent addons would be useful, but you can still delay all your loading stuff until your "addon" has actually finished loading. The easiest way is probably going to be to centralize it. Add a table to your addon's namespace to hold all the loading functions, in whichever file loads first:

Code:
local ADDON_NAME, addonNamespace = ...
addonName.loadFuncs = {}
Then in each other file, take all the code you're currently running in the main chunk, and wrap it in a function:

Code:
local ADDON_NAME, addonNamespace = ...

local function InitializeThisModule()
-- Do the stuff here
end
Then insert that function into the table you created:

Code:
tinsert(addonNamespace.loadFuncs, InitializeThisModule)
Finally, go back to the first file, and set up an event handler to wait for ADDON_LOADED and call all the loading functions when it fires:

Code:
local eventFrame = CreateFrame("Frame")
eventFrame:RegisterEvent("ADDON_LOADED")
eventFrame:SetScript("OnEvent", function(self, event, addon)
    if addon == ADDON_NAME then
        -- Call all the functions, in the order they were defined:
        for i = 1, #addonNamespace.loadFuncs do
              addonNamespace.loadFuncs[i]()
        end
        -- Remove all the functions so they can't be accidentally called again:
        wipe(addonNamespace.loadFuncs)
        -- Stop listening for more events since we're done:
        self:UnregisterEvent(event)
    end
end)
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
08-18-13, 08:52 PM   #23
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
Or make caelLib a separate addon and your other addon dependent on it
  Reply With Quote
08-18-13, 09:11 PM   #24
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Well, once you start making parts separate addons, you should just continue that process to its logical end and avoid the conglomo-mod situation altogether.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
08-19-13, 02:28 AM   #25
Caellian
A Frostmaul Preserver
 
Caellian's Avatar
Join Date: May 2006
Posts: 281
Originally Posted by Phanx View Post
Well, once you start making parts separate addons, you should just continue that process to its logical end and avoid the conglomo-mod situation altogether.
What you're basically saying is that what i've been doing for the past week is a bad thing ?

I was better off with every addon on its own instead of all in one ?
__________________
if (sizeof(workload) > sizeof(brain_capacity)) { die('System Overload'); }
  Reply With Quote
08-19-13, 01:49 PM   #26
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
I am also interested in why this is a bad idea. Maybe for the purpose of memory and cpu tracking, so you could evaluate efficiency, but other than that what would be the reason to make it into separate addons?
  Reply With Quote
08-19-13, 06:13 PM   #27
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Well, for one, putting your entire UI into one "addon" makes it annoying to maintain. You can't isolate parts to debug problems, for example. It also leads to sloppy coding, such as inter-dependencies (where something in File A depends on something in File B, but something else in File B depends on something in File A), whereas having each discrete part its own addon forces you to use scoping correctly. I believe this is one of the issues you're running into right now.

For another, it sucks for your users. Go look at most any popular "all in one" UI's comments, and you'll find people asking how they can use just the unit frames, or just the buff mod, or just some other part by itself. By shoving everything together, you're forcing users to use 500 features just to get the 5 they want. There's no good reason your unit frames should depend on your action bars, or vice versa, so you should just make each of those things their own addon, so they can be used independently. Having a central "core" that each of the other addons depends on is fine.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
08-19-13, 06:20 PM   #28
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
There are some examples of where this falls flat, as well: Cartographer was one such monolithic beast, which slowly died due to various pieces breaking one by one. Until Rythal took Carbonite over, it suffered the same fate. He has slowly been moving its functionality out to individual modules to ease maintenance and allow people to only use the portions they want.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Code loading priority help


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