WoW:AddOn loading process: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
No edit summary
m (Move page script moved page AddOn loading process to AddOn loading process without leaving a redirect)
 
(7 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Uitech}}
{{uiaddon}}
This document describes the WoW [[UI Customization]] aspect of load order for loading [[AddOn]]s. It covers when the WoW client first starts up, when AddOns load for the first time, and when user or WoW reloads the [[UI]]. The availability of the Lua environment at various points in the process is also detailed. The term '[[WoW Client]]' means: the WoW game program that's launched to play WoW.


<[[WoW AddOn]]
== General steps ==
# Initial Scan - When the WoW client first starts, a list of files and AddOn dependencies is built.
# AddOn Load - AddOn code is executed after the player selects a character and chooses to enter the world.
# After all AddOn code has been loaded, the saved variables are executed. ADDON_LOADED fires after each AddOn's SVs have been loaded.


This technical detail describes the order in which addon code is loaded when the client first starts up, or reloads the interface, as well as what information is available to the Lua environment at various points in the process.
=== Initial Scan ===
First, the WoW client scans through all of the folders in the '''Interface\AddOns''' directory, looking for sub-folders containing a valid [[TOC file]] with a '.toc' extension, and in turn then loads each AddOn's TOC file into memory. TOC files that were not found during this step cannot be loaded by the game later and only happens on client start-up. This makes it impossible to install additional AddOns, or load updated TOC files, without restarting the client. For a AddOn to be considered valid, it must have a single word folder directly in the '''Interface\AddOns''' folder, and must have a matching named '.toc' file, such as a 'MyAddon' folder with a 'MyAddOn.toc' underneath it.  That is all that is required.


The general outline:
=== AddOn Load ===
# When the client first starts, Interface\Addons directory is scanned, and a list of files and addon dependencies is built.
AddOn loading occurs when the player logs in. The dependency information in the .toc files is used, in part, to compute the order in which the AddOns files will be loaded, as well as the natural order in which the AddOns were discovered during the scan process. For AddOns with dependencies, an individual AddOn may '''not''' assume that all of the other AddOns that it depends on will be loaded first, without taking specific steps to ensure its dependencies are already loaded and available. When WoW loads a particular AddOn it uses the information in its [[TOC file]] discovered during initial scan and loads each file in order that it is found inside the TOC.
# Addon code is executed after the player selects a character.
# After all addon code has been loaded, the saved variables are executed. ADDON_LOADED fires after each addon's SVs have been loaded.


==The initial scan and addon loading order==
== Inside the TOC file ==
The client scans through the Interface\AddOns directory, storing a list of present files, and loading all .toc files into memory; files that were not found during this step cannot be loaded  by the game later. This step only happens on client start-up, which makes it impossible to install additional addons / update .toc files / add additional graphics and/or data files to addons without restarting the client.
Files within an AddOn are loaded in the order they're listed in the AddOn's [[TOC file]], named [addonname].toc. Files included through XML <Include file="src.xml" /> or <Script file="src.lua" /> are loaded at the time the tag is encountered while parsing. XML OnLoad script handlers execute when all of a widget's children have been created.
 
Dependency information in the .toc files is used to compute the order in which addons will be loaded when the player logs in. In most cases, an individual addon may assume that all of the addons that it depends on will be loaded first.
 
==Files within an addon==
Files within an addon are loaded in the order they're listed in the addon's .toc file. Files included through XML <Include file="src.xml" /> or <Script file="src.lua" /> are loaded at the time the tag is encountered while parsing. XML OnLoad script handlers execute when all of a widget's children have been created.


When the addon code is first loaded during this step, only basic information about the player -- name, class, race and realm -- is available.
When the addon code is first loaded during this step, only basic information about the player -- name, class, race and realm -- is available.
Line 22: Line 20:
To illustrate the loading order, consider the following addon code example:
To illustrate the loading order, consider the following addon code example:


<span style="font-size: 1.6em">LoadingOrder.toc</span>
 
'''LoadingOrder.toc'''
  ##Interface: 30000
  ##Interface: 30000
  ##Title: Loading Order Demo
  ##Title: Loading Order Demo
Line 28: Line 27:
  file2.xml
  file2.xml
  file3.lua
  file3.lua
<span style="font-size: 1.6em">file1.lua</span>
 
 
'''file1.lua'''
  print("This loads first")
  print("This loads first")
<span style="font-size: 1.6em">file2.xml</span>
 
 
'''file2.xml'''
  <Ui>
  <Ui>
   <Frame name="TemplateFrame" virtual="true">
   <Frame name="TemplateFrame" virtual="true">
     <Frames>
     <Frames>
Line 43: Line 47:
     </Frames>
     </Frames>
   </Frame>
   </Frame>
   <Frame inherits="TemplateFrame">
   <Frame inherits="TemplateFrame">
     <Frames>
     <Frames>
     <Frame>
     <Frame>
       <Scripts>
       <Scripts>
Line 52: Line 58:
       </Scripts>
       </Scripts>
     </Frame>
     </Frame>
     <Frame>
     <Frame>
       <Scripts>
       <Scripts>
Line 59: Line 66:
       </Scripts>
       </Scripts>
     </Frame>
     </Frame>
      <Scripts>
      <OnLoad>
        print("Parent frame's OnLoad fires after its children's.")
      </OnLoad>
      </Scripts>
     </Frames>
     </Frames>
    <Scripts>
    <OnLoad>
      print("Parent frame's OnLoad fires after its children's.")
    </OnLoad>
    </Scripts>
   </Frame>
   </Frame>
   <Script file="file2.5.lua"/>
   <Script file="file2.5.lua"/>
  </Ui>
  </Ui>
<span style="font-size: 1.6em">file2.5.lua</span>
 
 
'''file2.5.lua'''
  print("Files included in XML are executed as they are encountered");
  print("Files included in XML are executed as they are encountered");
<span style="font-size: 1.6em">file3.lua</span>
 
 
'''file3.lua'''
  print("This concludes this presentation");
  print("This concludes this presentation");


== Saved variables loading ==
== Saved variables loading ==
After the addon code has been loaded, the loading process can be followed by registering for various events, listed here in order of firing.
After the addon code has been loaded, the loading process can be followed by registering for various events, listed here in order of firing.
# [[Events A-B (ActionBar, Auction, AutoEquip, AutoFollow, Bag, BankFrame, BattleFields, Billing)#ADDON_LOADED|ADDON_LOADED]]
# [[Events/A#ADDON_LOADED|ADDON_LOADED]]
#* This event fires whenever an AddOn has finished loading and the SavedVariables for that AddOn have been loaded from their file.   
#* This event fires whenever an AddOn has finished loading and the SavedVariables for that AddOn have been loaded from their file.   
# [[Events S (Screenshot, Select, Send, Show, Skill, SpellsCast, Spell, Stop, Suggest, Sysmsg)#SPELLS_CHANGED|SPELLS_CHANGED]]
# [[Events/S#SPELLS_CHANGED|SPELLS_CHANGED]]
#* This event fires shortly before the [[Events P (Party, Petition, Pet, PlayerBank, Player)#PLAYER_LOGIN|PLAYER_LOGIN]] event and signals that information on the user's spells has been loaded and is available to the UI.   
#* This event fires shortly before the [[Events/P#PLAYER_LOGIN|PLAYER_LOGIN]] event and signals that information on the user's spells has been loaded and is available to the UI.   
# [[Events P (Party, Petition, Pet, PlayerBank, Player)#PLAYER_LOGIN|PLAYER_LOGIN]]
# [[Events/P#PLAYER_LOGIN|PLAYER_LOGIN]]
#* This event fires immediately before [[Events P (Party, Petition, Pet, PlayerBank, Player)#PLAYER_ENTERING_WORLD|PLAYER_ENTERING_WORLD]].
#* This event fires immediately before [[Events/P#PLAYER_ENTERING_WORLD|PLAYER_ENTERING_WORLD]].
#* Most information about the game world should now be available to the UI.
#* Most information about the game world should now be available to the UI.
#* All Sizing and Positioning of frames is supposed to be completed before this event fires.   
#* All Sizing and Positioning of frames is supposed to be completed before this event fires.   
#* AddOns that want to do one-time initialization procedures once the player has "entered the world" should use this event instead of [[Events P (Party, Petition, Pet, PlayerBank, Player)#PLAYER_ENTERING_WORLD|PLAYER_ENTERING_WORLD]].
#* AddOns that want to do one-time initialization procedures once the player has "entered the world" should use this event instead of [[Events/P#PLAYER_ENTERING_WORLD|PLAYER_ENTERING_WORLD]].
# [[Events P (Party, Petition, Pet, PlayerBank, Player)#PLAYER_ENTERING_WORLD|PLAYER_ENTERING_WORLD]]
# [[Events/P#PLAYER_ENTERING_WORLD|PLAYER_ENTERING_WORLD]]
#* This event fires immediately after [[Events P (Party, Petition, Pet, PlayerBank, Player)#PLAYER_LOGIN|PLAYER_LOGIN]]
#* This event fires immediately after [[Events/P#PLAYER_LOGIN|PLAYER_LOGIN]]
#* Most information about the game world should now be available to the UI. If this is an interface reload rather than a fresh log in, talent information should also be available.
#* Most information about the game world should now be available to the UI. If this is an interface reload rather than a fresh log in, talent information should also be available.
#* All Sizing and Positioning of frames is supposed to be completed before this event fires.   
#* All Sizing and Positioning of frames is supposed to be completed before this event fires.   
#* This event also fires whenever the player enters/leaves an instance and generally whenever the player sees a loading screen
#* This event also fires whenever the player enters/leaves an instance and generally whenever the player sees a loading screen
# [[Events P (Party, Petition, Pet, PlayerBank, Player)#PLAYER_ALIVE|PLAYER_ALIVE]]
# [[Events/P#PLAYER_ALIVE|PLAYER_ALIVE]]
#* This event fires after [[Events P (Party, Petition, Pet, PlayerBank, Player)#PLAYER_ENTERING_WORLD|PLAYER_ENTERING_WORLD]]
#* This event fires after [[Events/P#PLAYER_ENTERING_WORLD|PLAYER_ENTERING_WORLD]]
#* Quest and Talent information should now be available to the UI
#* Quest and Talent information should now be available to the UI



Latest revision as of 04:44, 15 August 2023

WoW AddOn

This document describes the WoW UI Customization aspect of load order for loading AddOns. It covers when the WoW client first starts up, when AddOns load for the first time, and when user or WoW reloads the UI. The availability of the Lua environment at various points in the process is also detailed. The term 'WoW Client' means: the WoW game program that's launched to play WoW.

General steps[edit]

  1. Initial Scan - When the WoW client first starts, a list of files and AddOn dependencies is built.
  2. AddOn Load - AddOn code is executed after the player selects a character and chooses to enter the world.
  3. After all AddOn code has been loaded, the saved variables are executed. ADDON_LOADED fires after each AddOn's SVs have been loaded.

Initial Scan[edit]

First, the WoW client scans through all of the folders in the Interface\AddOns directory, looking for sub-folders containing a valid TOC file with a '.toc' extension, and in turn then loads each AddOn's TOC file into memory. TOC files that were not found during this step cannot be loaded by the game later and only happens on client start-up. This makes it impossible to install additional AddOns, or load updated TOC files, without restarting the client. For a AddOn to be considered valid, it must have a single word folder directly in the Interface\AddOns folder, and must have a matching named '.toc' file, such as a 'MyAddon' folder with a 'MyAddOn.toc' underneath it. That is all that is required.

AddOn Load[edit]

AddOn loading occurs when the player logs in. The dependency information in the .toc files is used, in part, to compute the order in which the AddOns files will be loaded, as well as the natural order in which the AddOns were discovered during the scan process. For AddOns with dependencies, an individual AddOn may not assume that all of the other AddOns that it depends on will be loaded first, without taking specific steps to ensure its dependencies are already loaded and available. When WoW loads a particular AddOn it uses the information in its TOC file discovered during initial scan and loads each file in order that it is found inside the TOC.

Inside the TOC file[edit]

Files within an AddOn are loaded in the order they're listed in the AddOn's TOC file, named [addonname].toc. Files included through XML <Include file="src.xml" /> or <Script file="src.lua" /> are loaded at the time the tag is encountered while parsing. XML OnLoad script handlers execute when all of a widget's children have been created.

When the addon code is first loaded during this step, only basic information about the player -- name, class, race and realm -- is available.

To illustrate the loading order, consider the following addon code example:


LoadingOrder.toc

##Interface: 30000
##Title: Loading Order Demo
file1.lua
file2.xml
file3.lua


file1.lua

print("This loads first")


file2.xml

<Ui>

  <Frame name="TemplateFrame" virtual="true">
   <Frames>
    <Frame>
     <Scripts>
      <OnLoad>
        print("Inherited elements of the frame are processed first."); 
      </OnLoad>
     </Scripts>
    </Frame>
   </Frames>
  </Frame>

  <Frame inherits="TemplateFrame">
   <Frames>

    <Frame>
     <Scripts>
      <OnLoad>
        print("First child frame's OnLoad fires first")
      </OnLoad>
     </Scripts>
    </Frame>

    <Frame>
     <Scripts>
      <OnLoad>
        print("Second child frame's OnLoad fires second")
      </OnLoad>
     </Scripts>
    </Frame>

   </Frames>

   <Scripts>
    <OnLoad>
      print("Parent frame's OnLoad fires after its children's.")
    </OnLoad>
   </Scripts>
  </Frame>

  <Script file="file2.5.lua"/>
</Ui>


file2.5.lua

print("Files included in XML are executed as they are encountered");


file3.lua

print("This concludes this presentation");

Saved variables loading[edit]

After the addon code has been loaded, the loading process can be followed by registering for various events, listed here in order of firing.

  1. ADDON_LOADED
    • This event fires whenever an AddOn has finished loading and the SavedVariables for that AddOn have been loaded from their file.
  2. SPELLS_CHANGED
    • This event fires shortly before the PLAYER_LOGIN event and signals that information on the user's spells has been loaded and is available to the UI.
  3. PLAYER_LOGIN
    • This event fires immediately before PLAYER_ENTERING_WORLD.
    • Most information about the game world should now be available to the UI.
    • All Sizing and Positioning of frames is supposed to be completed before this event fires.
    • AddOns that want to do one-time initialization procedures once the player has "entered the world" should use this event instead of PLAYER_ENTERING_WORLD.
  4. PLAYER_ENTERING_WORLD
    • This event fires immediately after PLAYER_LOGIN
    • Most information about the game world should now be available to the UI. If this is an interface reload rather than a fresh log in, talent information should also be available.
    • All Sizing and Positioning of frames is supposed to be completed before this event fires.
    • This event also fires whenever the player enters/leaves an instance and generally whenever the player sees a loading screen
  5. PLAYER_ALIVE
    • This event fires after PLAYER_ENTERING_WORLD
    • Quest and Talent information should now be available to the UI

Until 3.0, VARIABLES_LOADED used to fire upon completion of the addon loading process; since 3.0, it is fired in response to CVars, Keybindings and other associated "Blizzard" variables being loaded, and may therefore be delayed until after PLAYER_ENTERING_WORLD. The event may still be useful to override positioning data stored in layout-cache.txt

Load On Demand behavior[edit]

Load on Demand addons cannot rely on most of the event sequence being fired for them; only ADDON_LOADED is a reliable indication that the saved variables for your LoD addon have been loaded.

See also[edit]

  • Handling events for information on how to sign up to receive event notifications