AddOn Structure

What goes into an AddOn, anyway? The answer may surprise you!

Learning Aid

a UI AddOn for

by Clement Cherlin

World of Warcraft AddOn Programming Basics

Blizzard provides AddOn developers with minimal information. The majority of the documentation accessible by the public has been derived by reading the Lua code included in the game, extracting strings from the game’s executable, and a substantial amount of trial-and-error. You can read more about AddOn development at the fan sites Wowpedia and World of Warcraft Programming, among others.

World of Warcraft AddOns consist of several text files. Every AddOn has a “Table of Contents” or .toc file that gives the AddOn’s name, provides a bit of information about it, specifies what version of the game the AddOn is compatible with, and lists the Lua and/or XML files in the AddOn’s subdirectory that the game should load. When the player runs World of Warcraft, the game opens each toc file and reads the list of Lua and/or XML files into memory.

When a player logs in to a game character, WoW refers to its list of AddOns and associated files. WoW opens each Lua or XML file one at a time, reads the contents into memory, and converts the human-readable text into binary representations of user-interface widgets, Lua functions, and data. At this time, each AddOn sets up the functions, data and UI widgets(link) that it will use later; loads any saved information from previous game sessions; registers its event handling functions, and the list of events it needs to be notified of.

Widgets and Events

World of Warcraft has an event-driven graphical user interface. In the built-in WoW UI and user-created AddOns, windows, buttons, sliders and text input boxes, known as widgets, each have a list of events associated with them. Lua scripts included with the game and each AddOn register their interest in these events, and Lua functions to call when those events occur. After the game engine renders the 3D world, but before it displays the finished image on the screen, it generates a list of events. Each event represents some change in the state of the game, like a character gaining or losing hit points, the player logging in or out, receiving a chat message, etc. The game calls these event handler functions to notify interested widgets that an event they are listening for has occurred. The event handlers then take whatever action is appropriate: they may adjust the state of buttons, update text and graphical indicators, show or hide themselves or other widgets, start or stop playing sounds, etc.