View Single Post
04/01/14, 07:10 PM   #8
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
EVENT_ADD_ON_LOADED fires when your addon has finished loading and your previously saved variables are ready to be accessed. Assume this is your addon below - I'll comment the order in which everything occurs.

YourAddon.txt
Code:
## Title: YourAddon

YourAddon.lua     --1: this file and its contents gets loaded into memory first
YourAddon.xml     --6: now that the above is finished, this file gets executed
YourAddon.lua - this file is loaded into memory from top to bottom
Lua Code:
  1. local myVar, counterLabel     --2: these local variables exist in memory now but haven't been assigned anything yet (nil)
  2.  
  3. --3: this function is loaded into memory but hasn't actually been called/run yet
  4. local function YourAddonInitialize()
  5.      EVENT_MANAGER:RegisterForEvent("YourAddon", EVENT_PLAYER_DEAD, YourAddonEvent)     --12: this other event gets registered for
  6.      counterLabel = WINDOW_MANAGER:CreateControl("YourAddonFrameCounter", YourAddonFrame, CT_LABEL)     --13: the label is now created (meanwhile, the OnUpdate script has tried to access it multiple times)
  7.      myVar = 0     --14: the counter is set to its initial value
  8. end
  9.  
  10. --4: the event is registered for, but hasn't fired yet, and so still hasn't called the function
  11. EVENT_MANAGER:RegisterForEvent("YourAddon", EVENT_ADD_ON_LOADED, function(event, addon)
  12.           if addon == "YourAddon" then     --11: your addon and its saved variables have finished loading, so EVENT_ADD_ON_LOADED fires and calls the initialize function since the addon argument matches the name of our addon now
  13.                YourAddonInitialize()
  14.           end
  15.      end)
  16.  
  17. --5: this function is loaded into memory but hasn't been called yet
  18. function YourAddonUpdate()     --9...: this begins to be called constantly starting with when the handler is set at #8 below
  19.      YourAddonFrameCounter:SetText(myVar)     --note it's trying to access the counter which still hasn't been created yet
  20.      myVar = myVar + 1
  21. end

YourAddon.xml - this file is executed from top to bottom
Code:
<GuiXml>
    <Controls>
        <TopLevelControl name="YourAddonFrame">     --7: your toplevel window is created
            <Dimensions x="200" y="42" />
            <Anchor point="CENTER" />
 
            <OnUpdate>
                YourAddonUpdate()     --8: your OnUpdate handler is set to this function - this now begins firing and calls this function according to your frame rate (50 times per second, if at 50fps)
            </OnUpdate>
 
            <Controls>
                <Backdrop name="$(parent)BG" inherits="ZO_ThinBackdrop" />     --10: the bg frame is created
            </Controls>
        </TopLevelControl>
    </Controls>
</GuiXml>

Now... this isn't the exact format that you described your addon to be, but am I close? Do you see the error(s)?
  Reply With Quote