Topic: UI AddOns 101 (Tutorials/explanations)
Well for all of you adventurous folks, heres a tutorial to get you going with AddOns. I will explain the basic purpose of each of the files, and later explain a simple clock AddOn.
In your World of Warcraft directory, there might be a folder called "Interface" (without the quotes), depending on how you installed it and whether or not you have AddOns installed currently. If this folder does not exist, you will need to create one. Inside this folder needs to be another folder called "AddOns", again, if it does not exist, create one. The AddOns folder holds all of the individual AddOn folders.
The individual AddOn folder contains 3 different files. The first is the .toc (Table of Contents) file. This file contains all the information necessary for the game to display the AddOn in the AddOns menu and load the AddOn into the game. There are 7 components to this file:
## Interface:
## Title:
## Notes:
## SavedVariables:
## Dependencies:
## OptionalDeps:
.xml
Interface specificies the interface version number that WoW is running at. This number is 4 digits long, currently being 10900.
Title has no effect on how the AddOn will run, it simply gives WoW a name to call it when necessary.
Notes is the description of the AddOn. Again, it does not effect how it runs.
SavedVariables is the variable names that will hold information between WoW sessions. These variables are stored in the savedvariables.lua file.
Dependencies specify what other AddOns need to be enabled for this AddOn to load.
OptionalDeps is optional dependencies, some AddOns have certain parts that will communicate with other AddOns or have special features if this AddOn is loaded. Don't worry about this line right now.
The last line (or lines) is the .xml file that the AddOn loads. If you want it to load more than one .xml file, have each on its own line.
The second file is the .xml file. This file contains the information for how the AddOn will appear. This contains which graphics to load, the size, position, etc. It also specifies the .lua script file to load and when to call the certain functions. This file will always be structured:
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.blizzard.com/wow/ui/">
(The layout stuff)
</Ui>
(Normally the whole <Ui xmlns...> line would go on one line, but I split it into 2 for viewing purposes.)
Dont worry about what each part of that tag means, its just information WoW uses.
As for the basic XML syntax relating to the WoW AddOns, each tag has a pair, <opening tag> and </closing tag>. Inbetween these two tags, there might be more tags which would be linked to the outer tags. For example:
<Frame name="george">
<Size>
<AbsDimension x="2" y="3">
</AbsDimension>
</Size>
</Frame>
This will create a frame named george with a size of 2x3. Each of the tags has its pair, but this code could also be written as:
<Frame name="george">
<Size>
<AbsDimension x="2" y="3"/>
</Size>
</Frame>
Notice that the AbsDimension tag no longer has its own pair shown, but has '/>' instead of only '>'. This combines the opening and closing tags together. Note: This will only work if you do not want any other tages to be inside it as it is closed before anything can be inside.
In order for WoW to know what script file to load to make the AddOn do something, you have to add the script tag.
<Script file="filename.lua"/>
This will tell it what script file to use, but not what functions to run and when. In order to do this, you need to add scripts tags like the following:
<Scripts>
<OnLoad>
OnLoad_Function();
</OnLoad>
<OnUpdate>
OnUpdate_Function(arg1);
</OnUpdate>
<OnEvent>
OnEvent_Function();
</OnEvent>
<OnDragStart>
OnDragStart_Function();
</OnDragStart>
<OnDragStop>
OnDragStop_Function();
</OnDragStop>
<OnMouseUp>
OnMouseUp_Function();
</OnMouseUp>
</Scripts>
These are pretty self-explanitory. The functions that it calls are located inside the .lua file, and the scripts that are run use .lua syntax.
The third file is the .lua file. This file contains all the scripts and functions that the AddOn uses to make it function. LUA is a very simple language and should not be hard to learn what you need.
--This is a comment, it starts with '--'
--A variable, it is set outside of a function, so it is global:
GLOBAL_VARIABLE = "hi";
--A function, starts with "function [function_name]()" and ends with "end":
function OnLoad_Function()
--Stuff to occur when function is ran goes in here of course, this one is called by the XML file when the addon loads
--This variable is called variable and its value is the string Bobby
variable = "Bobby";
end
This is just the basic LUA setup, I'll get into the specific code stuff in the clock tutorial which will come later.
-Oscar Wilde