Wowpedia

We have moved to Warcraft Wiki. Click here for information and the new URL.

READ MORE

Wowpedia
 
(Rewrite)
 
Line 1: Line 1:
  +
This tutorial describes how to write a very simple and very basic AddOn. As it's tradition with almost all programing languages, it'll be a "Hello, World!" AddOn.
−
{| class="darktable" align="center" style="margin:0 auto 1em auto; width:80%;" cellpadding="4"
 
−
|-
 
−
! colspan="2" style="text-align:center; font-size:120%;" |This is [[User:Pcj|Pcj]]'s [[Wowpedia:Talk page guidelines|talk page]], where you can leave messages and comments for Pcj.
 
−
|-
 
−
|
 
−
* '''[[Wowpedia:Signatures|Please sign and date your posts]]''' by typing four tildes (<tt><nowiki>~~</nowiki><nowiki>~~</nowiki></tt>).
 
−
* '''Put new text under old text.''' [{{fullurl:{{TALKPAGENAMEE}}|action=edit&section=new}} Click here to start a new topic].
 
−
*'''Do not repeatedly edit yours or others' contributions to my talk page with small changes, I get an e-mail every time you do.''' --{{User:Pcj/sig}}
 
−
*Previous discussions: [[User talk:Pcj/Archive 1]], [[User talk:Pcj/Archive 2]], [[User talk:Pcj/Archive 3]]
 
−
| class="title" style="text-align:left;" |
 
−
*[[Wowpedia:Wikiquette|Be polite]]
 
−
*[[Wowpedia:Assume good faith|Assume good faith]]
 
−
*[[Wowpedia:Please do not bite the newcomers|Be welcoming]]
 
−
|}
 
   
  +
'''Note:''' Writing an AddOn is an advanced task. You need to be able to work with your computer. This especially includes:
−
== Overhaul of Patch_mirrors page ==
 
  +
* Know what operating system you're using (i.e. "Windows" or "Mac OS X").
−
Blizzard is finally offering REAL patch files to 4.01.13164 & 4.0.1.13205, as evident by this page (Atomicgamer for instance offers those files too):
 
  +
* Know how to open a folder on your computer (either with the Windows Explorer on Windows or the Finder on MacOSX).
−
http://games.on.net/filelist.php?app=178&menu=1
 
  +
* Know how to generally use a text editor on your computer and save text files (you've written with this editor) to arbitrary folders.
  +
* Know what a file and a folder (a.k.a directory) is.
  +
* Know what something like "C:\Program Files\World of Warcraft\Patch.html" means (location of a file or folder).
   
  +
== Preparation ==
−
I believe it's time to edit the page so we can list patches for each region again, as before, not just those MPG & TFIL files.
 
  +
Writing an AddOn requires two pieces of software installed on your computer:
  +
* World of Warcraft
  +
* A text editor
   
  +
A text editor is used to edit plain text files (hence the name). They need to be distinguished from [http://en.wikipedia.org/wiki/Word_processor word processors]. Word processors allow text formatting (such as making text bold or italics). Thus they don't save plain text files but document files instead. On Windows, "Notepad" is a (very limited) text editor, whereas "Wordpad" and especially "Microsoft Word" are word-processor. You may use "Notepad", but you can't use "Wordpad" or "Microsoft Word".
−
== Existence WoWWiki ==
 
   
  +
The dozens of free text editors out there. You will want to use one that has [http://en.wikipedia.org/wiki/Syntax_highlighting Syntax Highlighting]. Here are some recommendations.
−
How long will WoWWiki be online yet? I may want to copy/paste articles from there when the articles there are more recent than those that have already been copied to here. [[User:Hans Kamp|Hans Kamp]] ([[User talk:Hans Kamp|talk]]) 19:10, 20 October 2010 (UTC)
 
  +
* ''On Windows:'' [http://notepad-plus-plus.org Notepad++] (freeware; highly recommended)
−
:Wikia will maintain WoWWiki indefinitely. --{{User:Pcj/sig}} 19:11, 20 October 2010 (UTC)
 
  +
* ''On Mac:'' [http://www.barebones.com/products/textwrangler/ TextWrangler]
−
::Okay, then I won't have to rush the editing of the articles. :) [[User:Hans Kamp|Hans Kamp]] ([[User talk:Hans Kamp|talk]]) 19:17, 20 October 2010 (UTC)
 
   
  +
'''Note:''' You can find more lua editors at the [[Lua editors|Lua editors overview page]]. However, some of them may be more than what we need for this tutorial. So the recommendations above only contain basic editors.
−
== An offer of service ==
 
   
  +
== The new AddOn ==
−
Now that we have made the transition - and I hope that Blizzard does too - I offer what service I can provide...such as it is. :) --[[User:Joshmaul|Joshmaul]] ([[User talk:Joshmaul|talk]]) 19:14, 20 October 2010 (UTC)
 
  +
All AddOns lives in a very specific folder called <tt>AddOns</tt>. This folder is located here:
−
:Um, thanks? Just change WoWWiki to Wowpedia where it makes sense to, as well as any other outdated stuff. --{{User:Pcj/sig}} 19:16, 20 October 2010 (UTC)
 
−
::Has there been a move to change the site on Blizzard's fansite listing? --[[User:Joshmaul|Joshmaul]] ([[User talk:Joshmaul|talk]]) 19:20, 20 October 2010 (UTC)
 
−
:::We're working on it. Kaydeethree is going to talk to them at Blizzcon. --{{User:Pcj/sig}} 19:24, 20 October 2010 (UTC)
 
   
  +
%WorldOfWarcraftFolder%\Interface\AddOns
−
== Edit Count Display and Quantity Errors ==
 
   
  +
where <tt>%WorldOfWarcraftFolder%</tt> is the location where World of Warcraft is installed on your computer. Usually the complete path looks like this:
−
Just happened to notice that the edit count is not showing on user pages and there is a significant discrepancy between the old and the new. Past that, grats on the move and I again think it is for the better in the long term. [[User:Ariule|Ariule]] ([[User talk:Ariule|talk]])
 
   
  +
* On Windows: <tt>C:\Program Files\World of Warcraft\Interface\AddOns</tt>
−
:Yeah, we're aware of the problem. Unfortunately, I don't think there's much that can be done. --{{User:Pcj/sig}} 00:06, 21 October 2010 (UTC)
 
  +
* On Mac: <tt>/Applications/World of Warcraft/Interface/AddOns</tt>
   
  +
Each AddOn has its own directory under the <tt>AddOns</tt> folder.
−
::If there is nothing to be done, then that is the way it shall be. Not a problem at all, just wanted it to be on the "aware" list. [[User:Ariule|Ariule]] ([[User talk:Ariule|talk]])
 
   
  +
Now go ahead and do these steps:
−
:::Did the edit counts get <i>completely</i> reset as it appears from this side? [[User:Ariule|Ariule]] ([[User talk:Ariule|talk]])
 
  +
# Create a directory for your AddOn called <tt>HelloWorld</tt>
−
::::They're reset, but obviously they can be re-figured from counting your contributions. Which is a big chore for as many users as we have. --{{User:Pcj/sig}} 01:18, 22 October 2010 (UTC)
 
  +
# Create three empty text files named: <tt>HelloWorld.toc</tt>, <tt>HelloWorld.lua</tt>, <tt>HelloWorld.xml</tt>
−
:::::Again, not a problem, It was fun watching the counter click and making it the 1k club was cool and all that. Perhaps a "Feat of Strength Achievement" seal and new seals for the new edit clubs. Just a thought. [[User:Ariule|Ariule]] ([[User talk:Ariule|talk]])
 
   
  +
Note that the only difference in the three file names is the suffix. These denote, in order:
−
== On Name Changes... ==
 
  +
* the [[TOC format|Table of Contents]] file (<tt>.toc</tt>)
−
Don't mean to be rude or anything, but if it's not too much trouble, could I maybe get my username changed to Teth? Thanks. -- [[Image:Inv_staff_81.png|20px|link=User:Sebreth]] [[User:Sebreth|Sebreth]] <span style="font-size:10px; color:aqua">([[User_talk:Sebreth|T]].[[Special:Contributions/Sebreth|C]])</span> 02:00, 21 October 2010 (UTC)
 
  +
* the [[Lua]] code file (<tt>.lua</tt>)
−
:Done. --{{User:Pcj/sig}} 02:01, 21 October 2010 (UTC)
 
  +
* the [[XML user interface]] visual elements file (<tt>.xml</tt>)
−
::Huh. I thought it'd be more of a bother than that. Thanks a ton, bro. -- [[Image:Inv_staff_81.png|20px|link=User:Teth]] [[User:Teth|Teth]] <span style="font-size:10px; color:aqua">([[User_talk:Teth|T]].[[Special:Contributions/Teth|C]])</span> 02:10, 21 October 2010 (UTC)
 
   
  +
'''Important:''' The name of your AddOn directory and the name on the <tt>.toc</tt> file must match.
−
== Rename ==
 
−
''Now that you're here, do you want a name change? You don't need the WoWWiki- prefix anymore. --{{User:Pcj/sig}} 04:03, 22 October 2010 (UTC)''
 
−
:Yes, please. Suzaku will suffice. [[User:WoWWiki-Suzaku|WoWWiki-Suzaku]] ([[User talk:WoWWiki-Suzaku|talk]]) 04:08, 22 October 2010 (UTC)
 
   
  +
The next steps are to fill these three text files with some content. This is what the text editor is used for. The content of each file is described in the next sections.
−
== Chrome search title ==
 
   
  +
=== The .toc or Table of Contents ===
−
Congrats on the move! I wanted to report an error I noticed earlier searching the site via the Google Chrome omnibar. Quick recap: Chrome recognizes searches on a site, and thenceforth when it sees you typing the url it will offer you the ability to press tab and enter keywords to search using the site's search functionality. When you do press tab, Chrome places an icon on the left side of the omnibar that says "Search [site name]:". ''When I searched Wowpedia for the first time, [site name] is still "WoWWiki" according to Chrome.'' I don't know where it pulls this name from, but apparently it didn't get changed over. Threw me for a loop for a second. I'm aware you can change this name manually, which I've done, but obviously the default should be fixed.
 
  +
This file tells WoW about your AddOn: what files to load and what order to load them in. Later you will want to have a look at the [[TOC format]] page for all of the gory details about what you can put into this file. For now we are just using some basic stuff.
   
  +
Using your trusted text file editor, place the following into the <tt>HelloWorld.toc</tt> file:
−
TLDR: The Chrome omnibar search functionality still calls Wowpedia "WoWWiki".
 
   
  +
## Interface: 40000
−
...and grr, it looks like I'm unable to repro this; when I delete the search from Chrome and make it re-generate it, "wowpedia.org" is displayed now. Still could be because of my edit though, so I guess I'll let you guys take a look at it just to be sure. Perhaps you fixed it already. [[User:Jerodast| - Jerodast]] ([[User talk:Jerodast|talk]]) 08:09, 21 October 2010 (UTC)
 
  +
## Title: Hello World!
  +
## Notes: My first AddOn
  +
HelloWorld.lua
  +
HelloWorld.xml
   
  +
This content should be pretty self-explanatory (except for the first line; see below):
−
== Sidebar & Other Graphical Improvements ==
 
  +
* The lines starting with <tt>##</tt> are called ".toc tags" and provide basic information about the AddOn.
  +
* The other two lines (not starting with <tt>##</tt>) tell WoW which files belong to the AddOn (here <tt>HelloWorld.lua</tt> and <tt>HelloWorld.xml</tt>).
  +
* Lines starting with <tt>#</tt> (only one hash; not contained in the example above) are considered comments and are ignored by WoW.
   
  +
So, starting from the first line we are saying:
−
Hi Pcj,<br>
 
  +
# The compatible UI version for this addon is 40000 (or 4.0.x)
−
Congrats on the move and a new shiny Vector skin.<br>
 
  +
# The title of the addon to be displayed in game is "Hello World!"
−
If you are wondering how to have a 100% customisable sidebar with minimal fuss, Aionopedia uses an extensions named CustomNavBlocks or sumthing like that.<br>
 
  +
# The description of the addon to be displayed in game are the notes
−
Also for the edit article box that in typing this in, you may want to consider using the UsabilityInitiative until they have a easily plug-in for CKEditor.<br>
 
  +
# HelloWorld.lua file will be loaded.
−
If you want sum help with customising the Vector skin i know it very well and more than help you out.
 
  +
# HelloWorld.xml file will be loaded.
−
Aionopedia [[User:Bohtauri|Bohtauri]] ([[User talk:Bohtauri|talk]]) 13:44, 22 October 2010 (UTC)
 
−
:Not particularly interested, thanks. --{{User:Pcj/sig}} 13:44, 22 October 2010 (UTC)
 
   
  +
A few notes on the first line:
−
== Wikia reference in DNP policy ==
 
   
  +
## Interface: 40000
−
Hiya! Just randomly trawling around the new site (love it, btw), and came across a reference to Wikia's ToU (and a broken link, to boot). Specifically, in the [[http://www.wowpedia.org/Wowpedia:DNP_policy#Other_prohibitions_enforced_by_this_policy DNP Policy]] article. I'm not sure where that link really should point, and it's an important enough part of the policies that I really ''don't'' want to get it wrong. So, the next best option seems to be "alert an admin". Well, consider yourself alerted. :) --[[User:PaxArcana|PaxArcana]] ([[User talk:PaxArcana|talk]]) 04:57, 23 October 2010 (UTC)
 
   
  +
By the time you try to follow this tutorial, that value will probably have changed and you will need to put in the current value. If you've got WoW running, you can find out this number by running the following command:
−
== ru.wow.wikia.com -> www.wowpedia.ru ==
 
   
  +
/run print((select(4, GetBuildInfo())))
−
Please modify interwiki links. We did it on www.wowpedia.ru. Thx. [[User:Strizh|Strizh]] ([[User talk:Strizh|talk]]) 13:22, 23 October 2010 (UTC)
 
−
:Will do, most of the Curse staff is busy with Blizzcon atm so it may be next week. --{{User:Pcj/sig}} 13:23, 23 October 2010 (UTC)
 
−
:OK, now it's done. There seems to be some sort of hidden "job queue" while it goes through all the pages. --{{User:Pcj/sig}} 03:36, 27 October 2010 (UTC)
 
−
:: Please modify interwiki links from wowpedia.ru to www.wowpedia.ru (trouble with search engine indexes). Thx. [[User:Strizh|Strizh]] ([[User talk:Strizh|talk]]) 08:31, 9 November 2010 (UTC)
 
   
  +
If not, may look into the .toc files of some other AddOns you've installed or have a look at [[Getting the current interface number]].
−
==User Account Migration==
 
   
  +
What is this number? It's the user interface (UI) version for the AddOn. The "40000" is version 4.0.x (where x is an arbitry number). This number tells WoW that your AddOn is compatible with the current WoW version (or the current Blizzard UI level to be more precise). If your UI number does not match the Blizzard UI number, your AddOn will be considered out of date. This number exists to minimize problems caused by out of date AddOns. Those AddOns won't be loaded automatically anymore.
−
Hi there. Just following up on [[User_talk:Starlightblunder#User_Account_Migration|this discussion]], where foxlit mentioned some Perl scripts you used to import user accounts. I was just wondering if you could let me know how this worked, and what you used? Many thanks [[User:Adam|Adam]] ([[User talk:Adam|talk]]) 11:27, 24 October 2010 (UTC)
 
   
  +
For more details on stuff you can put in here, please visit the [[TOC format]] page.
−
== Multiple File Upload Page Broken ==
 
   
  +
=== The .lua or Lua code file ===
−
Recieve the following error with both FireFox and IE
 
  +
The <tt>.lua</tt> files are where the main "what to do" instructions for the AddOn reside. You will see a variety of terms for this "what to do" such as "logic", "executable code", or simply "code" (in most cases). Lua code does its thing in response to something that happens in the game. Things that happen in the game are called "events".
   
  +
==== Events ====
−
<code>Fatal error: Call to undefined method UploadForm::UploadForm() in /home/wowpedia/public_html/extensions/MultiUpload/SpecialMultipleUpload.body.php on line 72</code>
 
  +
There are two basic kinds of events.
  +
# The first kind of event is when something happens in the game. This might be somebody saying something, something happening to your character, another character's stats changing, etc. Nearly everything that happens in the game causes events.
  +
# The second kind of event is when you do something to a UI Element (a UI Element is something on the screen - like a button - and is affectionately called a widget. We'll get to that more in the next section). This second kind of event might be clicking on something in your bags or button bar.
   
  +
There is a technical difference between the two types of events, and we will discuss that as the tutorial progresses. For more details on the first kind of event see [[Events (API)]] and for the second see [[Widget handlers]].
−
Posted it here [[Forum:Multiple_upload_page_error|Forum:Multiple Upload Page Error]] But was unsure if in the chaos of the move it may simply have been overlooked.
 
   
  +
This discussion of events is extremely important because absolutely nothing happens in the game except in response to an event.
−
Please advise. [[User:Ariule|Ariule]] ([[User talk:Ariule|talk]]) 01:26, 26 October 2010 (UTC)
 
   
  +
'''Important:''' Should you happen to write a piece of code that runs for an extended time (perhaps forever) absoultely nothing new will happen in the game. The game will freeze, nothing will move anymore, and the user will not be able click anything anymore. That would be classified as "not good".
−
== e-mail validation not working ==
 
   
  +
So, how do you tell World of Warcraft that you are interested in a particular event? There are two ways: First, you can tell WoW which piece of code to run when a particular event happens. This is called registering your event. Second, you can tell the XML to run a piece of code when a UI Element is manipulated (such as clicking on it or moving your mouse over it). These pieces of code that run in response to events are called "functions" (or more precisly "event handlers").
−
Hey there, since you "pulled" me over, I thought I'd make it your problem :p<br>
 
−
Taking over my account here worked fine, except setting my e-mail address seems to cause some troubles => I don't receive the validation e-mail. Now I don't know whether gmail blocks it or wowpedia does not send it, but I just checked the spam to be sure. So maybe there's a problem with the mailserver setup? -[[User:Watchout|watchou]][[User_talk:Watchout|T]] 02:25, 26 October 2010 (UTC)
 
   
  +
==== Functions ====
−
: great, a classic. Just tried again and this time it worked... So everything's fine the prim is back -[[User:Watchout|watchou]][[User_talk:Watchout|T]] 02:28, 26 October 2010 (UTC)
 
  +
Functions are groupings of code that accomplish a specific purpose. On one hand, there are numerous pre-defined functions provided by WoW. They're called "API functions" (API = Application Programming Interface). And on the other hand you can make your own user-defined functions.
−
:Nice. :) --{{User:Pcj/sig}} 02:29, 26 October 2010 (UTC)
 
   
  +
While there are multiple ways to create functions in Lua, the easiest to understand looks like this:
−
== Nested sidebar site navigation ==
 
   
  +
[local] function ''function_name''(<zero or more arguments>)
−
Please see [[MediaWiki talk:Sidebar]]. --[[User:Timeshifter|Timeshifter]] ([[User talk:Timeshifter|talk]]) 09:08, 29 October 2010 (UTC)
 
  +
... code ...
  +
end
   
  +
* The <tt>[local]</tt> is an optional keyword that limits the visibility of the function to a particular scope. Scope will be covered in more depths shortly.
−
:http://www.wowwiki.com/MediaWiki:Monaco-sidebar has been archived here:
 
  +
* The ''function_name'' is simply a name you make up so you can reference your function from other places in your AddOn.
−
:* [[User:Timeshifter/Monaco-sidebar]]
 
  +
* The <tt>&lt;zero or more arguments&gt;<tt> are the way to pass information into the function. This is what gives functions their power. Each time you call the function, you can supply a different set of arguments and get different results based upon them.
  +
* The <tt>... code ...<tt> is where the work gets done in a function. Here is where you do calculations, comparisons, call other functions, etc to get the task of the function done.
  +
* The <tt>end</tt> keyword simply marks the end of the definition of the function.
   
  +
Note that this only defines the function. The function is not actually run until some other piece of code calls it.
−
:I think [[MediaWiki:Sidebar]] here could be opened in edit mode, and some or all of the old Monaco site navigation could be added to the bottom. I believe the Vector skin would automatically put nearly all of it in nested form. With open/close arrows. I am curious if that is true. If that is true, then if things don't work out at Wikia I may move my wiki to a wiki farm that has the Vector skin. I don't know how long it will be though, before the MediaWiki-based wiki farms upgrade to version 1.16 of MediaWiki. I believe version 1.16 is the first non-beta version with the Vector skin as the default skin. --[[User:Timeshifter|Timeshifter]] ([[User talk:Timeshifter|talk]]) 22:55, 30 October 2010 (UTC)
 
   
  +
For more information on functions, please see the [http://www.lua.org/manual/5.1/ Lua 5.1 Reference Manual] or
−
== Item template is causing infinite loop ==
 
  +
[http://www.lua.org/pil/ Programming in Lua (first edition)]. Also see the [[Lua]] page which lists more Lua resources.
   
  +
==== HelloWorld.lua ====
−
I tried to use that template in [[Patch_4.0.3_(undocumented_changes)]] but why does it cause an infinite loop? In [[User:Hans_Kamp/Test]] and here it doesn't: {{item|icon=|Peacebloom}}. Please try to fix it. Then I will see what changes you made to prevent the loop. [[User:Hans Kamp|Hans Kamp]] ([[User talk:Hans Kamp|talk]]) 06:34, 30 October 2010 (UTC)
 
  +
Now to continue with our "Hello, World" code example, put the following into your <tt>HelloWorld.lua</tt> file and save it.
−
:This was caused because of the missing of the tooltip of [[Justice point]]. The tooltip is placed at the left. That needs yet to be fixed. I wonder how you will fix it, because copying the text of the article to a new one places the tooltip to the left for reasons, not known by me. [[User:Hans Kamp|Hans Kamp]] ([[User talk:Hans Kamp|talk]]) 07:13, 30 October 2010 (UTC)
 
−
::Fixed it myself. The name parameter of {{t|tooltip}} must be exactly the same (case sensitive) as the article name. [[User:Hans Kamp|Hans Kamp]] ([[User talk:Hans Kamp|talk]]) 07:50, 30 October 2010 (UTC)
 
   
  +
function HelloWorld()
−
== Had to Re-login again. ==
 
  +
print("Hello World!");
  +
end
   
  +
You should understand everything in here by now. This function is named HelloWorld and it has zero arguments. The code part is simply the <tt>print("Hello World!");</tt> portion. And it ends with <tt>end</tt>.
−
Hey Pcj, its me Sairez, I was doing some edits and noticed that I while I cruising the site I was logged out and I didn't log myself out. I don't why it logged me out. --[[User:Sairez|Sairez]] ([[User talk:Sairez|talk]]) 04:12, 31 October 2010 (UTC)
 
   
  +
This is a fine piece of code, but by itself it's useless unless something calls this function. Onward to UI Elements (aka Widgets).
−
== Banning Sannse ==
 
   
  +
=== The .xml or XML visual elements file ===
−
Good day Pcj, I would ask you to reconsider your recent ban of Sannse. While I'm aware that it is in response to events at WoWWiki, I would suggest that we should not allow ourselves to stoop to their level. Let Wikia's foolish actions expose themselves for who they are, and let the community judge with its choice of where to go. We don't need to do anything to help them shoot themsleves in the foot. They (Wikia) do a good job of that on their own these days. For your consideration, [[User:Ddcorkum|Ddcorkum]] ([[User talk:Ddcorkum|talk]]) 02:25, 3 November 2010 (UTC)
 
  +
"UI Elements", or "Widgets", are all of the tiny bits of graphics that make up the User Interface. WoW uses XML to layout everything that you see on the screen. Additionally, when things happen (called "events", remember?) to the widgets on the screen, event handlers (i.e. functions) can be called to perform whatever action you want. We will see shortly how we tell WoW which widgets we are interested in and which events we want to be handled by which event handler.
−
:See [http://www.wowwiki.com/index.php?title=Forum:Next_steps_for_WoWWiki&curid=296961&diff=2417814&oldid=2417806 this edit] for the reason. --<span style="border-bottom: 1px dotted;cursor:help;" title="Wowpedia bureaucrat">[[User:Kaydeethree|k]]_[[User_talk:Kaydeethree|d]]<sup>[[Special:Contributions/Kaydeethree|3]]</sup></span> 02:27, 3 November 2010 (UTC)
 
−
::Seen -- I guessed it was in relation to that, but admittedly when I read Sannse' comment I don't understand what the "problem" is exactly. Is it that contributions were copied over? [[User:Ddcorkum|Ddcorkum]] ([[User talk:Ddcorkum|talk]]) 02:29, 3 November 2010 (UTC)
 
−
:::If you could figure out what Sannse's actually saying I'd award you an internet or two. --<span style="border-bottom: 1px dotted;cursor:help;" title="Wowpedia bureaucrat">[[User:Kaydeethree|k]]_[[User_talk:Kaydeethree|d]]<sup>[[Special:Contributions/Kaydeethree|3]]</sup></span> 02:34, 3 November 2010 (UTC)
 
−
::::"This problem" = Sannse being on Wowpedia? Sannse editing Wowpedia while being associated with Sannse (as opposed to a fresh sockpuppet)? Wowpedia as a whole? I want an internet... Edit: Based on kd3's comment/hint, does Sannse think that we would use the copied account for slander?--{{User:Sandwichman2448/Sig}} 03:33, 3 November 2010 (UTC)
 
   
  +
==== Blizzard XML format declared ====
−
== Thank you. ==
 
  +
For those of you who don't know: XML stands for "eXtensible Markup Language" and is a means of tagging content with identifiers.
  +
What identifiers exist and how they're organized can be defined in something called an "XML Schema". In our case, we want to create
  +
XML documents that WoW will understand, so we will use the XML Schema provided by Blizzard for the Wow User Interface.
   
  +
We declare that our document conforms to the Blizzard schema with the following bit of magic:
−
Thank you for taking your time to look over my work and edit where you saw fit.
 
−
it helps me a lot to see what mistakes i've made and all for i am still new to editing and adding information to this site. though i plan to be a heavy contributer.
 
   
  +
<nowiki>
−
[[User:Kinaria|Kinaria]] ([[User talk:Kinaria|talk]]) 18:58, 8 November 2010 (UTC)
 
  +
<Ui xmlns="http://www.blizzard.com/wow/ui/"
−
:Whoops, sorry, it's at [[Magma Plated Battlearmor (heroic)]] now. --{{User:Pcj/sig}} 19:11, 8 November 2010 (UTC)
 
  +
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  +
xsi:schemaLocation="http://www.blizzard.com/wow/ui/
  +
http://wowprogramming.com/FrameXML/UI.xsd">
  +
</Ui></nowiki>
   
  +
The exact meaning of all of the above is beyond the scope of this tutorial. Consider it a magic formula that you always put in every.xml file you will create for the WoW user interface. For those of you that like to reformat things, the first three lines can be merged to line line (use spaces), but the fourth line (<tt>http://wowprogramming.com/FrameXML/UI.xsd"&gt;</tt>) needs to be on a line by itself starting in column 1.
−
== Question about making New item Pages. ==
 
   
  +
There are a few general notes that you need to know about concerning XML, particularly as it is used by WoW.
−
When i make a new Item page.. i copy the entire page of an Old item and just make name and stat changes and then when i save it.. the item box is on the left side of the page when it should be on the Right side. how do i fix this? {{Unsigned|Kinaria}}
 
  +
The generalized format of a "tag" is:
−
:The item name in the tooltip has to match the name of the page, or you have to use the disambigpage parameter. See {{t|tooltip}} for more details. --{{User:Pcj/sig}} 20:24, 8 November 2010 (UTC)
 
   
  +
<tagname attribute="attribute value" anotherattribute="anotherattribute value">
  +
  +
</tagname>
   
  +
A tag must have a tagname, and it may have zero or more attributes along with the attributes' associated values in double quotes.
−
thank you!
 
  +
The tag is everything between the ''''<tagname'''' and the trailing ''''>''''. The tag is closed by an "end tag" with the same name as the tag (i.e. ''''</tagname>''''). Tagnames do not have spaces and are case sensitive. A valid tagname might be 'BackgroundWidgets', whereas 'backgroundwidgets' would not be valid.
−
[[User:Kinaria|Kinaria]] ([[User talk:Kinaria|talk]]) 20:25, 8 November 2010 (UTC)
 
−
:BTW, this is case sensitive. [[User:Hans Kamp|Hans Kamp]] ([[User talk:Hans Kamp|talk]]) 20:42, 8 November 2010 (UTC)
 
   
  +
Blizzard defines all valid tagnames in their [http://wowprogramming.com/FrameXML/UI.xsd UI.xsd]. The [[XML user interface]] page has a good list under [[XML user interface#Widget Elements|Widget Elements]] which will aid you until we get further along.
−
== Cannot make edits anymore. ==
 
   
  +
Everything between the tag and the end tag is the ''content'' of the tag. Everything. Even other tags along with their content.
−
When I do an edit to an article, I get "Sorry! We could not process your edit due to a loss of session data. Please try again. If it still does not work, try logging out and logging back in." [[User:Hans Kamp|Hans Kamp]] ([[User talk:Hans Kamp|talk]]) 10:54, 9 November 2010 (UTC)
 
  +
In the case where there is no content to a tag, the tag can be shorted to <tt>&lt;tagname /&gt;</tt> instead of <tt>&lt;tagname&gt;&lt;/tagname&gt;</tt> though both versions are valid. A complete tag with no content looks like:
   
  +
<tagname attribute="attribute value" anotherattribute="anotherattribute value"/>
−
== Broken template? ==
 
   
  +
Using the above piece of magic as an example, we can see that there is a tag with the name ''''Ui'''' and that it has three attributes (the funny forth line is a part of the third attribute). Content is represented by the space between the end of the tag (the ''''>'''' on the fourth line) and the ''''</Ui>'''' end tag.
−
It seems the template - {{cost|a-hp=1337}} - (or whatever this is) intended for the currency "Honor Point" redirects to the in-game location with the same name instead. Just click the pic and you'll notice. I don't know how to fix it, but perhaps you do? Just thought I'd mention it. {{unsigned|WrathOfDeathfrost}}
 
−
:Fixed. --{{User:Pcj/sig}} 17:53, 10 November 2010 (UTC)
 
−
::Argh, one second too late on adding my signature which I noticed I'd forgotten... but thanks for the help! [[User:WrathOfDeathfrost|WrathOfDeathfrost]] ([[User talk:WrathOfDeathfrost|talk]]) 17:58, 10 November 2010 (UTC)
 
   
−
== Your userpage ==
+
==== HelloWorld.xml ====
  +
Now to continue with our "Hello, World" XML example, put the following text in your <tt>HelloWorld.xml</tt>:
   
  +
<nowiki><Ui xmlns="http://www.blizzard.com/wow/ui/"
−
'''''"There's a problem with your tooltips/the AJAX RC..."'''''<br>
 
  +
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
−
''"...or Wikia changed something..."''
 
  +
xsi:schemaLocation="http://www.blizzard.com/wow/ui/
  +
..\..\FrameXML\UI.xsd"></nowiki>
  +
  +
</Ui>
   
  +
Now before we create the frame for our addon, we have to add a simple line of code that tells the WoW engine where to find our function in our <tt>.lua</tt> file. Notice this is a tag with no content, which gets a '/>' and no end tag. This is because this tag doesn't require any additional content (other than the name of the file).
−
While I agree they fail on a depressingly regular basis, they won't be responsible for any problems now. Update? :-)
 
   
  +
<Script File="HelloWorld.lua"/>
−
Sorry for bothering you over something so trivial, when I get bored I just wander around the wiki so occasionally notice stuff like this. [[File:A_F_K_sig_2.jpg|50px|link=User:A_F_K_When_Needed]] [[User:A_F_K_When_Needed|A F K]] [[User_talk:A_F_K_When_Needed|When]] [[Special:Contributions/A_F_K_When_Needed|Needed]] 21:11, 11 November 2010 (UTC)
 
−
:Good catch, thanks. --{{User:Pcj/sig}} 21:13, 11 November 2010 (UTC)
 
   
  +
WoW connects everything to a frame, even other frames. So, in order to create something that WoW will interact with,
−
== Content needs revising since the split. ==
 
  +
we create a frame:
   
  +
<Frame name="HelloWorldFrame">
−
Hey, i was looking at [[Wowpedia:FAQ#Chat]] and noticed some of it hasn't been revised since the split, and is now out-of-date, was going to edit it, but im not sure what to change it to. {{User:Mosios/sig}} 14:57, 13 November 2010 (UTC)
 
  +
  +
</Frame>
   
  +
The tagname is ''''Frame'''' and we have used the ''''name'''' attribute and given the attribute the value of ''''HelloWorldFrame''''.
−
== Faction split quest pages ==
 
   
  +
Our frame tag is included as content to the Ui tag and so goes between the start Ui tag and the end Ui tag. To help keep track of what is surrounding what, we indent the content with respect to the enclosing tags like this:
−
Noticed your edits of the Elemental Unrest Phase 4 quest pages, looks like WoWWiki never had that sort of nifty faction integration. [[User:Deepred|Deepred]] ([[User talk:Deepred|talk]]) 01:05, 17 November 2010 (UTC)
 
   
  +
<nowiki><Ui xmlns="http://www.blizzard.com/wow/ui/"
−
==A question about one of your latest templates==
 
  +
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
−
Hello, I found this template today: {{t|Faction switch}}. It's been a time since I've wanted to make my own template with that "switch window" feature, but only a few wikis used it, and it was a mess of a code. It's the first time I see it at WoWPedia, and it seems easier than I originally expected.
 
  +
xsi:schemaLocation="http://www.blizzard.com/wow/ui/
  +
..\..\FrameXML\UI.xsd"></nowiki>
  +
<Script File="HelloWorld.lua"/>
  +
<Frame name="HelloWorldFrame">
  +
  +
</Frame>
  +
</Ui>
   
  +
It is very important that you do not mix up the various end tags and indenting helps keep things straight. Notice that the ''''Frame'''' and ''''Script'''' tag are completely surrounded by the ''''Ui'''' tag.
−
Would you mind explaining (shortly) how it works, or linking some tutorial? (I'm not sure how this functionality is called, so it's hard to find anything around it)
 
   
  +
Inside the frame, one of the many things we can define are Scripts. Scripts are nothing more than small pieces of Lua code. Where we place the script determines when it will be invoked. Because Scripts live within a Frame we include the ''''Scripts'''' tag inside the ''''Frame'''' tag. Notice the difference, in the ''''Scripts'''' tag, the 's' sets it apart from the ''''Script'''' tag.
−
My main objective is to apply it to {{t|Bookfooter}}, allowing you to see the different sections without having to open new articles. If it works, I could try making something similar for {{t|Dungeons}} (currently being discussed as to be split or not).
 
   
  +
<Frame name="HelloWorldFrame">
−
Hope you can lend me a hand. Thanks from advance :P.--[[User:Lon-ami|Lon-ami]] ([[User talk:Lon-ami|talk]]) 13:06, 18 November 2010 (UTC)
 
  +
<Scripts>
  +
  +
</Scripts>
  +
</Frame>
   
  +
The various widgets have several Events that can occur and if we want to declare a Widget Handler to process the event we include the event name under the Scripts tag of the widget we are interested in. Not every widget has the same set of events. In this example, we are interested in an event named ''''OnLoad''''. The OnLoad event happens when the widget is loaded into the UI. For this example, we want the OnLoad event to run the script named HelloWorld. This script was defined in the HelloWorld.lua as a function.
−
==Category Deletion==
 
−
I noticed you deleted [[:Category:Casual guilds]], however we currently have both [[:Category:PvP guilds]] and [[:Category:PvE guilds]]. If we're willing to have guild pages broken down in that manner, why would Casual or RP guilds not have the same treatment? [[User:Hooper|Hooper]] ([[User talk:Hooper|talk]]) 17:14, 23 November 2010 (UTC)
 
−
:RP guilds do receive the same treatment, casual guilds are not the same type of breakdown. --{{User:Pcj/sig}} 17:16, 23 November 2010 (UTC)
 
−
::May I ask that you explain your reasoning a bit? I would argue that they are the exact same type of breakdown, being one of the only four types of guilds I've ever heard of in four years of playing, and seeing the term used exactly the same as the three categories of guilds we currently have when guilds recruit. [[User:Hooper|Hooper]] ([[User talk:Hooper|talk]]) 17:19, 23 November 2010 (UTC)
 
−
:::So what do you think of when you say "casual"? You do both PvE and PvP - maybe a little RP? Then put all the categories on there. I'm not seeing the issue. --{{User:Pcj/sig}} 17:20, 23 November 2010 (UTC)
 
−
::::Casual is exactly what the term means. To place one of the other terms would imply that a guild actively pursues to be that type, like PvE, PvP, and RP guilds do - which is why they use those terms when advertising. A casual guild may do both but is not actively pursuing to do them or defining their entire guild structure around one or the other. Its not a big deal, I just don't understand why it wouldn't be given the same treatment. [[User:Hooper|Hooper]] ([[User talk:Hooper|talk]]) 17:27, 23 November 2010 (UTC)
 
   
  +
<Scripts>
−
== Kirsten Westmill and future pages. ==
 
  +
<OnLoad>
  +
HelloWorld();
  +
</OnLoad>
  +
</Scripts>
   
  +
Take a look at the [[Widget handlers]] page for a list of widgets and the events you can write widget handlers for.
−
I took a picture of her when I gathered the info, but I couldn't find it when I was checking my screenshot folder. Thanks for uploading picture of her, I appreciate it!! I'll be updating any new NPCs/Mobs I found since the new patch. Thanks for the welcoming as well! [[User:Killmehorde|Killmehorde]] ([[User talk:Killmehorde|talk]]) 17:55, 27 November 2010 (UTC)
 
   
  +
The complete <tt>HelloWorld.xml</tt> file should look like this:
−
== Just thoguht you should be aware ==
 
   
  +
<nowiki><Ui xmlns="http://www.blizzard.com/wow/ui/"
−
A user decided to do some vandalizing on his way out of WoWWiki over to Wowpedia. http://www.wowwiki.com/Special:Contributions/Takakenji [[User:Deadlykris|Deadlykris]] ([[User talk:Deadlykris|talk]]) 15:58, 29 November 2010 (UTC)
 
  +
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  +
xsi:schemaLocation="http://www.blizzard.com/wow/ui/
  +
..\..\FrameXML\UI.xsd"></nowiki>
  +
<Script File="HelloWorld.lua"/>
  +
<Frame name="HelloWorldFrame">
  +
<Scripts>
  +
<OnLoad>
  +
HelloWorld();
  +
</OnLoad>
  +
</Scripts>
  +
</Frame>
  +
</Ui>
   
  +
There is an important thing you should note in the code above. The '''''HelloWorld();''''' is the only piece which is NOT a tag or an attribute. It is important to note that content in a WoW .xml UI document is always a piece of code if it is not another set of tags and their associated attributes. The only valid place for a piece of code is under the tag for an event.
−
== Obsolte quests protocol ==
 
   
  +
Having gotten this far, it is time to run your new AddOn.
−
Could you help me find the policies governing pages covering now obsolete questlines, NPCs, etc.? I'm looking for pages to clean up and there are still a lot of them about quests that no longer exist. Are we preserving this information? Let me know how I can help out! (You can respond here or on my talk page, whichever is easier.) -- [[User:Metaneira|Metaneira]] ([[User talk:Metaneira|talk]]) 20:55, 2 December 2010 (UTC)
 
−
: Quick follow-up: if we add the {{t|Removedfromgame}} template, should we remove the other categories? I would think that the "Quests in Feralas" category, for example, should only contain current quests, but what's the policy? -- [[User:Metaneira|Metaneira]] ([[User talk:Metaneira|talk]]) 21:07, 2 December 2010 (UTC)
 
−
:: And one more question -- I'm assuming that some categories are added from templates (e.g., [[Quest:Natural Materials]]). Do we have an obsolete questbox template to use that won't populate categories? Or do I just remove the questbox? (Sorry for bugging you so much!) -- [[User:Metaneira|Metaneira]] ([[User talk:Metaneira|talk]]) 21:38, 2 December 2010 (UTC)
 
   
  +
=== Running your HelloWorld AddOn ===
−
== [[Magni Bronzebeard]] ==
 
  +
You should now have a folder called "HelloWorld" in your "AddOns" folders, and in that folder there should be three files named <tt>HelloWorld.toc</tt>, <tt>HelloWorld.lua</tt>, and <tt>HelloWorld.xml</tt>. The contents of these three files should be ''exactly'' as listed above.
   
  +
Now start World of Warcraft and log into your account, but don't select your character yet.
−
Why does it have "==== &lt;!-- Don't remove --&gt; ====" creating empty calories in the TOC? I figured I'd ask the nearest admin since you left my welcome message. --[[User:Espantish|Espantish]] ([[User talk:Espantish|talk]]) 04:13, 6 December 2010 (UTC)
 
  +
Please click the red ''''AddOns'''' button on the lower left of the character selection screen to see all of the AddOns WoW has detected. There will be one for every folder in your AddOns directory except for the AddOns starting with "Blizzard_".
−
:Huh, that's annoying. Thanks for pointing it out, we'll look at it. --{{User:Pcj/sig}} 04:14, 6 December 2010 (UTC)
 
−
::Alright, cool. While I have your attention, is there a script or some tool people use to import item and quest data? I'd like to help if I can, but I don't want to bang my head against any tables unnecessarily. --[[User:Espantish|Espantish]] ([[User talk:Espantish|talk]]) 04:48, 6 December 2010 (UTC)
 
−
::Someone else answered on my talk page. Thanks anyway! Keep up the good work. --[[User:Espantish|Espantish]] ([[User talk:Espantish|talk]]) 05:49, 6 December 2010 (UTC)
 
   
  +
You should see your new HelloWorld in this list. The name should be yellow, and the checkbox to the left should be checked.
−
== [[Wowpedia:Autoconfirmed users]] ==
 
   
  +
If the name is Red and you see an '''Out of date''' message to the right, you probably didn't change the '''## Interface: 40000'''
−
Is this not true? It says I am an autoconfirmed user. [[User:Funny Bunny|Funny Bunny]] ([[User talk:Funny Bunny|talk]]) 01:45, 7 December 2010 (UTC)
 
  +
line in your <tt>HelloWorld.toc</tt> (as described [[#The .toc or Table of Contents|above]]). Please review that section and make the appropriate change.
−
:Well, you portrayed it incorrectly, the effect is unintentional if it exists. Not that it matters much for now. --{{User:Pcj/sig}} 01:51, 7 December 2010 (UTC)
 
   
  +
I do not recommend running your AddOns with the 'Load out of date AddOns' checkbox checked. That's asking for trouble as an AddOn that attempts to use old UI features can corrupt a new UI. Nearly every patch that changes the UI level has had problems with old AddOns that have not been updated to conform to the new UI standards.
−
== Sockpuppet blocking ==
 
   
  +
If you don't see your new AddOn at all, make sure that you have placed the HelloWorld folder in the right folder (called "AddOns") and that the files inside the "HelloWorld" folder have the right names and contents.
−
I'm assuming you're using CheckUser to determine this? --[[Image:gengar orange 22x22.png]]&nbsp;[[User:Fandyllic|Fandyllic]] <small>([[User talk:Fandyllic|talk]] &middot; [[Special:Contributions/Fandyllic|contribs]])</small> 10:13 PM PST 6 Dec 2010
 
−
:Why do you care? Yes. --{{User:Pcj/sig}} 05:14, 7 December 2010 (UTC)
 
   
  +
A note for windows users: make sure that you don't accidentially save your files as "HelloWorld.toc.txt" (instead of "HelloWorld.toc") etc. There is an option in windows explorer will hide the <tt>.txt</tt> suffix.
−
== Recent Armory link changes ==
 
   
  +
Please note the case (upper-case vs. lower-case letters) of the names of your folder and files: While Windows is insensitive to case for folder and file names, the case may be important on a Mac. Also, inside the game itself, World of Warcraft is sensitive to the case for the names of its variables and filenames. Keep the case the same to avoid problems.
−
Looks like you changed all the old wowarmory.com links to use the new battle.net URL's. There's just one problem. In the URL the realm names and character names need to be lower cased; otherwise, you get a big "character not found" error page. Edit: Or not, it appears to be something else. Edit again: Oh, it's a dash rather than a plus for a space in realm's name. —[[User:Egingell|<span class="ajaxttlink">EGingell</span>]]<sup>[[User_talk:Egingell|T]][[Special:Contributions/Egingell|C]]</sup> [http://us.battle.net/wow/en/character/cenarion-circle/treader/ Treader of Cenarion Circle] 21:51, 7 December 2010 (UTC)
 
−
:Meh, it wasn't working anyway. I tried a couple of links and they seemed to work, though. --{{User:Pcj/sig}} 21:53, 7 December 2010 (UTC)
 
   
  +
Now, you have a yellow "HelloWorld!" AddOn showing up in your AddOn list. Note the ! in the name. The name of the AddOn shown in this list is taken from the '''## Title: Hello World!''' line in the <tt>HelloWorld.toc</tt> file. In the future, we will see how to change colors and languages.
−
Spaces are converted to "-" and apostrophes are stripped (Anub'arak => Anubarak and Cenarion Circle => Cenarion-Circle); however, the URL is not case-sensitive. It's quite dumb, really. —[[User:Egingell|<span class="ajaxttlink">EGingell</span>]]<sup>[[User_talk:Egingell|T]][[Special:Contributions/Egingell|C]]</sup> [http://us.battle.net/wow/en/character/cenarion-circle/treader/ Treader of Cenarion Circle] 22:23, 7 December 2010 (UTC)
 
   
  +
If you move your mouse cursor over the HelloWorld name, you should see a tool-tip pop up with two lines in it. The first line is the same as the title, and the second line is taken from the '''## Notes: My first AddOn''' line in the .toc file. This can also be customized for color and language.
−
== Support from Blizzard? ==
 
   
  +
Cancel out of the AddOns display and enter the world with any of your characters. Once your character loads, you should see a message in the default chat window that says '''Hello, World!''' .
−
The other day I was having a look at my characters on battle.net. Hovering over a profession will display two external links for that profession, to Wowhead and Wowpedia (which I guess you know anyway...). I know wowhead is pretty popular, but it surprised me they had included Wowpedia. I thought Blizzard were hesitant when it came to supporting Wowpedia, which is why Wowpedia is hosted by Curse instead. Have they mentioned anything else concerning any cooperation, or did it just appear out of the blue? [[User:WrathOfDeathfrost|WrathOfDeathfrost]] ([[User talk:WrathOfDeathfrost|talk]]) 12:41, 18 December 2010 (UTC)
 
  +
  +
Success!!
  +
  +
== Review ==
  +
You have created your first AddOn and have successfully run it. Now let's review a bit about what was accomplished.
  +
  +
The 'Hello World!' text is taken from the line in the HelloWorld.lua file that reads 'print("Hello World!");'.
  +
Wrapped around that is a function named print which is responsible for displaying the text in the default chat window.
  +
  +
The print function is inside a function we created called HelloWorld that had no parameters. Our function will do the same thing every time
  +
it is called.
  +
  +
You should then recall that the name of our function was placed in the HelloWorld.xml file as the action to be taken when the ''Onload'' event
  +
of the ''Scripts'' tag of the Frame we created. We placed the name of our function in this specific place because we wanted our function to be
  +
executed (run, called, processed) when our Frame was fully loaded.
  +
  +
World of Warcraft knew that it should create our Frame because we placed the name of the .xml file into the .toc file.
  +
The .toc file must have the same name as the AddOn's directory and is the first of the files in our AddOn that Blizzard processes.
  +
  +
Inside the .toc file is where we tell World of Warcraft about our AddOn (the ## statements) and what files that need to be loaded.
  +
Every line that does not start with a ## is a file to be processed by World of Warcraft.
  +
The order that the file names appear is important because World of Warcraft processes the file in order listed.
  +
  +
Knowing that, we place the .lua file before the .xml file because we want the function HelloWorld declared (or defined) before we try to
  +
call it in the .xml file.
  +
  +
Even though this is a trivial example of an AddOn , important concepts and information have been covered.
  +
Further pages in this tutorial will cover other areas and expand upon topics initially presented here.
  +
  +
== More ==
  +
* [[AddOn programming tutorial]] - The index page. Also contains references used throughout this tutorial.
  +
[[Category:Interface customization]]
  +
[[Category:UI]]

Revision as of 17:30, 18 December 2010

This tutorial describes how to write a very simple and very basic AddOn. As it's tradition with almost all programing languages, it'll be a "Hello, World!" AddOn.

Note: Writing an AddOn is an advanced task. You need to be able to work with your computer. This especially includes:

  • Know what operating system you're using (i.e. "Windows" or "Mac OS X").
  • Know how to open a folder on your computer (either with the Windows Explorer on Windows or the Finder on MacOSX).
  • Know how to generally use a text editor on your computer and save text files (you've written with this editor) to arbitrary folders.
  • Know what a file and a folder (a.k.a directory) is.
  • Know what something like "C:\Program Files\World of Warcraft\Patch.html" means (location of a file or folder).

Preparation

Writing an AddOn requires two pieces of software installed on your computer:

  • World of Warcraft
  • A text editor

A text editor is used to edit plain text files (hence the name). They need to be distinguished from word processors. Word processors allow text formatting (such as making text bold or italics). Thus they don't save plain text files but document files instead. On Windows, "Notepad" is a (very limited) text editor, whereas "Wordpad" and especially "Microsoft Word" are word-processor. You may use "Notepad", but you can't use "Wordpad" or "Microsoft Word".

The dozens of free text editors out there. You will want to use one that has Syntax Highlighting. Here are some recommendations.

Note: You can find more lua editors at the Lua editors overview page. However, some of them may be more than what we need for this tutorial. So the recommendations above only contain basic editors.

The new AddOn

All AddOns lives in a very specific folder called AddOns. This folder is located here:

%WorldOfWarcraftFolder%\Interface\AddOns

where %WorldOfWarcraftFolder% is the location where World of Warcraft is installed on your computer. Usually the complete path looks like this:

  • On Windows: C:\Program Files\World of Warcraft\Interface\AddOns
  • On Mac: /Applications/World of Warcraft/Interface/AddOns

Each AddOn has its own directory under the AddOns folder.

Now go ahead and do these steps:

  1. Create a directory for your AddOn called HelloWorld
  2. Create three empty text files named: HelloWorld.toc, HelloWorld.lua, HelloWorld.xml

Note that the only difference in the three file names is the suffix. These denote, in order:

Important: The name of your AddOn directory and the name on the .toc file must match.

The next steps are to fill these three text files with some content. This is what the text editor is used for. The content of each file is described in the next sections.

The .toc or Table of Contents

This file tells WoW about your AddOn: what files to load and what order to load them in. Later you will want to have a look at the TOC format page for all of the gory details about what you can put into this file. For now we are just using some basic stuff.

Using your trusted text file editor, place the following into the HelloWorld.toc file:

## Interface: 40000
## Title: Hello World!
## Notes: My first AddOn
HelloWorld.lua
HelloWorld.xml

This content should be pretty self-explanatory (except for the first line; see below):

  • The lines starting with ## are called ".toc tags" and provide basic information about the AddOn.
  • The other two lines (not starting with ##) tell WoW which files belong to the AddOn (here HelloWorld.lua and HelloWorld.xml).
  • Lines starting with # (only one hash; not contained in the example above) are considered comments and are ignored by WoW.

So, starting from the first line we are saying:

  1. The compatible UI version for this addon is 40000 (or 4.0.x)
  2. The title of the addon to be displayed in game is "Hello World!"
  3. The description of the addon to be displayed in game are the notes
  4. HelloWorld.lua file will be loaded.
  5. HelloWorld.xml file will be loaded.

A few notes on the first line:

## Interface: 40000

By the time you try to follow this tutorial, that value will probably have changed and you will need to put in the current value. If you've got WoW running, you can find out this number by running the following command:

/run print((select(4, GetBuildInfo())))

If not, may look into the .toc files of some other AddOns you've installed or have a look at Getting the current interface number.

What is this number? It's the user interface (UI) version for the AddOn. The "40000" is version 4.0.x (where x is an arbitry number). This number tells WoW that your AddOn is compatible with the current WoW version (or the current Blizzard UI level to be more precise). If your UI number does not match the Blizzard UI number, your AddOn will be considered out of date. This number exists to minimize problems caused by out of date AddOns. Those AddOns won't be loaded automatically anymore.

For more details on stuff you can put in here, please visit the TOC format page.

The .lua or Lua code file

The .lua files are where the main "what to do" instructions for the AddOn reside. You will see a variety of terms for this "what to do" such as "logic", "executable code", or simply "code" (in most cases). Lua code does its thing in response to something that happens in the game. Things that happen in the game are called "events".

Events

There are two basic kinds of events.

  1. The first kind of event is when something happens in the game. This might be somebody saying something, something happening to your character, another character's stats changing, etc. Nearly everything that happens in the game causes events.
  2. The second kind of event is when you do something to a UI Element (a UI Element is something on the screen - like a button - and is affectionately called a widget. We'll get to that more in the next section). This second kind of event might be clicking on something in your bags or button bar.

There is a technical difference between the two types of events, and we will discuss that as the tutorial progresses. For more details on the first kind of event see Events (API) and for the second see Widget handlers.

This discussion of events is extremely important because absolutely nothing happens in the game except in response to an event.

Important: Should you happen to write a piece of code that runs for an extended time (perhaps forever) absoultely nothing new will happen in the game. The game will freeze, nothing will move anymore, and the user will not be able click anything anymore. That would be classified as "not good".

So, how do you tell World of Warcraft that you are interested in a particular event? There are two ways: First, you can tell WoW which piece of code to run when a particular event happens. This is called registering your event. Second, you can tell the XML to run a piece of code when a UI Element is manipulated (such as clicking on it or moving your mouse over it). These pieces of code that run in response to events are called "functions" (or more precisly "event handlers").

Functions

Functions are groupings of code that accomplish a specific purpose. On one hand, there are numerous pre-defined functions provided by WoW. They're called "API functions" (API = Application Programming Interface). And on the other hand you can make your own user-defined functions.

While there are multiple ways to create functions in Lua, the easiest to understand looks like this:

[local] function function_name(<zero or more arguments>)
   ... code ...
end
  • The [local] is an optional keyword that limits the visibility of the function to a particular scope. Scope will be covered in more depths shortly.
  • The function_name is simply a name you make up so you can reference your function from other places in your AddOn.
  • The <zero or more arguments> are the way to pass information into the function. This is what gives functions their power. Each time you call the function, you can supply a different set of arguments and get different results based upon them.
  • The ... code ... is where the work gets done in a function. Here is where you do calculations, comparisons, call other functions, etc to get the task of the function done.
  • The end keyword simply marks the end of the definition of the function.

Note that this only defines the function. The function is not actually run until some other piece of code calls it.

For more information on functions, please see the Lua 5.1 Reference Manual or Programming in Lua (first edition). Also see the Lua page which lists more Lua resources.

HelloWorld.lua

Now to continue with our "Hello, World" code example, put the following into your HelloWorld.lua file and save it.

function HelloWorld() 
  print("Hello World!"); 
end 

You should understand everything in here by now. This function is named HelloWorld and it has zero arguments. The code part is simply the print("Hello World!"); portion. And it ends with end.

This is a fine piece of code, but by itself it's useless unless something calls this function. Onward to UI Elements (aka Widgets).

The .xml or XML visual elements file

"UI Elements", or "Widgets", are all of the tiny bits of graphics that make up the User Interface. WoW uses XML to layout everything that you see on the screen. Additionally, when things happen (called "events", remember?) to the widgets on the screen, event handlers (i.e. functions) can be called to perform whatever action you want. We will see shortly how we tell WoW which widgets we are interested in and which events we want to be handled by which event handler.

Blizzard XML format declared

For those of you who don't know: XML stands for "eXtensible Markup Language" and is a means of tagging content with identifiers. What identifiers exist and how they're organized can be defined in something called an "XML Schema". In our case, we want to create XML documents that WoW will understand, so we will use the XML Schema provided by Blizzard for the Wow User Interface.

We declare that our document conforms to the Blizzard schema with the following bit of magic:

 <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/
 http://wowprogramming.com/FrameXML/UI.xsd">
 </Ui>

The exact meaning of all of the above is beyond the scope of this tutorial. Consider it a magic formula that you always put in every.xml file you will create for the WoW user interface. For those of you that like to reformat things, the first three lines can be merged to line line (use spaces), but the fourth line (http://wowprogramming.com/FrameXML/UI.xsd">) needs to be on a line by itself starting in column 1.

There are a few general notes that you need to know about concerning XML, particularly as it is used by WoW. The generalized format of a "tag" is:

<tagname attribute="attribute value" anotherattribute="anotherattribute value">

</tagname>

A tag must have a tagname, and it may have zero or more attributes along with the attributes' associated values in double quotes. The tag is everything between the '<tagname' and the trailing '>'. The tag is closed by an "end tag" with the same name as the tag (i.e. '</tagname>'). Tagnames do not have spaces and are case sensitive. A valid tagname might be 'BackgroundWidgets', whereas 'backgroundwidgets' would not be valid.

Blizzard defines all valid tagnames in their UI.xsd. The XML user interface page has a good list under Widget Elements which will aid you until we get further along.

Everything between the tag and the end tag is the content of the tag. Everything. Even other tags along with their content. In the case where there is no content to a tag, the tag can be shorted to <tagname /> instead of <tagname></tagname> though both versions are valid. A complete tag with no content looks like:

<tagname attribute="attribute value" anotherattribute="anotherattribute value"/>

Using the above piece of magic as an example, we can see that there is a tag with the name 'Ui' and that it has three attributes (the funny forth line is a part of the third attribute). Content is represented by the space between the end of the tag (the '>' on the fourth line) and the '</Ui>' end tag.

HelloWorld.xml

Now to continue with our "Hello, World" XML example, put the following text in your HelloWorld.xml:

<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/ 
 ..\..\FrameXML\UI.xsd">

</Ui> 

Now before we create the frame for our addon, we have to add a simple line of code that tells the WoW engine where to find our function in our .lua file. Notice this is a tag with no content, which gets a '/>' and no end tag. This is because this tag doesn't require any additional content (other than the name of the file).

<Script File="HelloWorld.lua"/>

WoW connects everything to a frame, even other frames. So, in order to create something that WoW will interact with, we create a frame:

<Frame name="HelloWorldFrame">

</Frame>

The tagname is 'Frame' and we have used the 'name' attribute and given the attribute the value of 'HelloWorldFrame'.

Our frame tag is included as content to the Ui tag and so goes between the start Ui tag and the end Ui tag. To help keep track of what is surrounding what, we indent the content with respect to the enclosing tags like this:

<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/ 
 ..\..\FrameXML\UI.xsd">
  <Script File="HelloWorld.lua"/>
  <Frame name="HelloWorldFrame">

  </Frame>
</Ui> 

It is very important that you do not mix up the various end tags and indenting helps keep things straight. Notice that the 'Frame' and 'Script' tag are completely surrounded by the 'Ui' tag.

Inside the frame, one of the many things we can define are Scripts. Scripts are nothing more than small pieces of Lua code. Where we place the script determines when it will be invoked. Because Scripts live within a Frame we include the 'Scripts' tag inside the 'Frame' tag. Notice the difference, in the 'Scripts' tag, the 's' sets it apart from the 'Script' tag.

 <Frame name="HelloWorldFrame">
  <Scripts>

  </Scripts>
 </Frame>

The various widgets have several Events that can occur and if we want to declare a Widget Handler to process the event we include the event name under the Scripts tag of the widget we are interested in. Not every widget has the same set of events. In this example, we are interested in an event named 'OnLoad'. The OnLoad event happens when the widget is loaded into the UI. For this example, we want the OnLoad event to run the script named HelloWorld. This script was defined in the HelloWorld.lua as a function.

  <Scripts>
   <OnLoad>
    HelloWorld();
   </OnLoad>
  </Scripts>

Take a look at the Widget handlers page for a list of widgets and the events you can write widget handlers for.

The complete HelloWorld.xml file should look like this:

<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/ 
 ..\..\FrameXML\UI.xsd">
  <Script File="HelloWorld.lua"/>
  <Frame name="HelloWorldFrame">
   <Scripts>
    <OnLoad>
     HelloWorld();
    </OnLoad>
   </Scripts>
  </Frame>
</Ui> 

There is an important thing you should note in the code above. The HelloWorld(); is the only piece which is NOT a tag or an attribute. It is important to note that content in a WoW .xml UI document is always a piece of code if it is not another set of tags and their associated attributes. The only valid place for a piece of code is under the tag for an event.

Having gotten this far, it is time to run your new AddOn.

Running your HelloWorld AddOn

You should now have a folder called "HelloWorld" in your "AddOns" folders, and in that folder there should be three files named HelloWorld.toc, HelloWorld.lua, and HelloWorld.xml. The contents of these three files should be exactly as listed above.

Now start World of Warcraft and log into your account, but don't select your character yet. Please click the red 'AddOns' button on the lower left of the character selection screen to see all of the AddOns WoW has detected. There will be one for every folder in your AddOns directory except for the AddOns starting with "Blizzard_".

You should see your new HelloWorld in this list. The name should be yellow, and the checkbox to the left should be checked.

If the name is Red and you see an Out of date message to the right, you probably didn't change the ## Interface: 40000 line in your HelloWorld.toc (as described above). Please review that section and make the appropriate change.

I do not recommend running your AddOns with the 'Load out of date AddOns' checkbox checked. That's asking for trouble as an AddOn that attempts to use old UI features can corrupt a new UI. Nearly every patch that changes the UI level has had problems with old AddOns that have not been updated to conform to the new UI standards.

If you don't see your new AddOn at all, make sure that you have placed the HelloWorld folder in the right folder (called "AddOns") and that the files inside the "HelloWorld" folder have the right names and contents.

A note for windows users: make sure that you don't accidentially save your files as "HelloWorld.toc.txt" (instead of "HelloWorld.toc") etc. There is an option in windows explorer will hide the .txt suffix.

Please note the case (upper-case vs. lower-case letters) of the names of your folder and files: While Windows is insensitive to case for folder and file names, the case may be important on a Mac. Also, inside the game itself, World of Warcraft is sensitive to the case for the names of its variables and filenames. Keep the case the same to avoid problems.

Now, you have a yellow "HelloWorld!" AddOn showing up in your AddOn list. Note the ! in the name. The name of the AddOn shown in this list is taken from the ## Title: Hello World! line in the HelloWorld.toc file. In the future, we will see how to change colors and languages.

If you move your mouse cursor over the HelloWorld name, you should see a tool-tip pop up with two lines in it. The first line is the same as the title, and the second line is taken from the ## Notes: My first AddOn line in the .toc file. This can also be customized for color and language.

Cancel out of the AddOns display and enter the world with any of your characters. Once your character loads, you should see a message in the default chat window that says Hello, World! .

Success!!

Review

You have created your first AddOn and have successfully run it. Now let's review a bit about what was accomplished.

The 'Hello World!' text is taken from the line in the HelloWorld.lua file that reads 'print("Hello World!");'. Wrapped around that is a function named print which is responsible for displaying the text in the default chat window.

The print function is inside a function we created called HelloWorld that had no parameters. Our function will do the same thing every time it is called.

You should then recall that the name of our function was placed in the HelloWorld.xml file as the action to be taken when the Onload event of the Scripts tag of the Frame we created. We placed the name of our function in this specific place because we wanted our function to be executed (run, called, processed) when our Frame was fully loaded.

World of Warcraft knew that it should create our Frame because we placed the name of the .xml file into the .toc file. The .toc file must have the same name as the AddOn's directory and is the first of the files in our AddOn that Blizzard processes.

Inside the .toc file is where we tell World of Warcraft about our AddOn (the ## statements) and what files that need to be loaded. Every line that does not start with a ## is a file to be processed by World of Warcraft. The order that the file names appear is important because World of Warcraft processes the file in order listed.

Knowing that, we place the .lua file before the .xml file because we want the function HelloWorld declared (or defined) before we try to call it in the .xml file.

Even though this is a trivial example of an AddOn , important concepts and information have been covered. Further pages in this tutorial will cover other areas and expand upon topics initially presented here.

More

  • AddOn programming tutorial - The index page. Also contains references used throughout this tutorial.