Friday, 19 March 2010

WoW in an Hour: Write an Addon

Last week I spent a couple of hours on WoW playing Narcolious with all the others from Single Abstract Noun. I spent a couple of hours and I only killed 3 mobs in the whole time. Some of that time was spent chatting, some setting up my UI, others going back to Ironforge to train and finally get a flaming horse for him - however the rest of that time I spent with the help of Phaerae testing out and fixing up an addon - namely my addon MTarget. Explaining MTarget is rather complex so I'm going to leave that to a later post - in its simplest form it can be thought of as a focus replacement (allowing multiple focus targets) - through the rewriting of macros.

If you don't have a lot of time to play and developing/coding/etc is something you enjoy then I can highly recommend it. MTarget is now onto its second version - the first never really made it out of beta - but did the job it needed to (the second version is now into its final beta stage). I started rewriting the whole thing while I was on my last break from WoW and have been working on it on and off since my return to playing. Occasionally I would dedicate an evening to sorting out the bugs - and that is what I did this week - finally getting around to testing and making sure that the broadcasting was working - and picking up a few bugs along the way (like I had forgotten to actually check if the debug setting was on/off before outputting the debug information - more chat spam? yes please).

One of the positives of doing this as a player with limited time is that I can make use of time, when I can't play WoW, to do some coding. Those of you that have been through any sort of programming course of some description have probably come across the term CABTAB - or Code a bit, Test a bit - which is generally not considered the best way to do things because you don't end up getting a consistent implementation from top to bottom but bits and pieces cobbled together. I remember back at uni, for the assignment I got my best mark in, I had got to uni the day it was due, decided it was crap and rewrote the whole thing in a text editor in the general computing labs. Only after I had finished the whole rewrite did I go to a computer lab to compile and test it. Therefore coding when you aren't in front of WoW can actually be beneficial to the process.

The other thing to remember is that you don't always have to be working on it. If it isn't working yet or you're not in the mood you can just dabble with little bits at a time (fix one bug then get on with something else), or disable the add-on and you're free to do other things. This is one reason why it has taken me so long to get my add-on back into action - it certainly hasn't been the focus of my WoW time!

Learn a new language
Stories of WoW has a post up of wow and languages - talking about using WoW to learn new languages (as in spoken language) - you as a developer can to! WoW add-ons are written in Lua - I had never used it before starting to code my add-ons, but quickly picked it up. So take the opportunity to learn something new. It is a well structure (yet flexible) interpreted language with similarities to other many other languages so you can pick it up easily. The formal Lua documentation isn't too bad either! It is currently quite popular as the scripting language for games so if you are looking to move into game development it is a good thing to have under your belt! Eclipse supports Lua if you like an IDE for developing in (I'm happy with vim which does have syntax highlighting for it too).

Learning to code?
I've seen two situations where people have been thrown into the deep end when it comes to programming. One of my units at uni "Computer Graphics and Image Processing" was opened up to the multimedia students and watching them flail about as they tried to learn how to program at the same time as actually doing some pretty complex 3D graphics programming was painful. Equally painful, I watched my wife trying to learn Fortran for a maths computing unit... I ended up writing most of her assignments (but she managed to pass the exams all by herself!). Even now she watches me when I work from home and wonders how the heck I understand what I'm doing - it all looks like a foreign language... and it is. So is coding a WoW add-on the place to learn about programming?

Sadly, I would say no. There is a lack of documentation, and Lua, while a great language, is not the place to start - I would recommend a compiled language over an interpreted one - simply because you can usually get more meaningful messages out of a compiled language through the act of compiling (converting the written text into something the computer understands). I'd start with something like Pascal (it has some parallels to Lua as well) - it was written to be a teaching language and it was where I started many moons ago (actually not technically true - I started my first programming in some weird language I can't even recall on a Microbee computer and then moved to qbasic on my first PC).

The one thing going for starting out with an add-on would be motivation - you may not have any motivation to write Hello World in Pascal but getting a message popping up within WoW that says hello to you might be all the motivation you need. I know when teaching music these days they'll often teach the popular songs first to in-still a sense of excitement and motivate the pupil to learn more about music... rather than starting with scales. The same can apply.

Getting Started
There is nothing more I can say about getting started other than... just do it! Give it a try, fail, succeed, fail again, keep trying and you'll learn. If I look through my projects folder I have so many failed projects - its in my nature to start things (usually with a brilliant idea) and then stop once I've learnt what I wanted to learn. But keep trying!

Start small
If you are interested into getting into add-on development then I will pull out yet another one of my uni maxims - KISS - Keep it Simple Stupid! Start with something simple and don't set your goals too high (I fail at this so much... so take my advice with a grain of salt - knowing that I'm a bad offender!) I've developed three main add-ons in my time - MTarget is the only one that is road worthy I might add. But I started simple. My first add-on goes back a while to when I was levelling my warrior. Basically to make it easier to use Overpower I created an add-on that switched my buttons around if I got an Overpower proc ("awesome give me some of that" you say - sorry but this was in vanilla WoW - what I was doing has not been possible since patch 2.2). This was simple and was generally working (it had issues if you went left combat with the Overpower buff up) but it introduced me to the basics of add-on development.

The other add-on I've developed was even simpler, called SwitchTracker, and I knocked it up in a few minutes purely as a proof of concept that you can actually mine and herb at the same time - just by automating the switching of your tracking. It doesn't have any configuration etc, but it wasn't intended to be used in production (I was just arguing my point over on the Wowhead UI & Macro Forums). If you do want this functionality someone in that thread recommended Spotter.

It doesn't have to be a beautiful unique snowflake
While you are learning don't be afraid to reinvent the wheel. Try your hand at implementing something that already exists - or just a part of it. I was recently re-reading a thread on the same forum when I was trying to remember the name of an add-on (Livestock) and one of the forum members mentioned that he had written his own version. When queried why he did this his answer was simply that all the add-ons suggested do much more than what he needed (which added to memory usage, and potential lag etc).

Make improvements to an existing add-on
Most add-ons have a list a mile long of improvements that commenters have suggested. You can make a start on add-on development by working on another add-on. I've done this in the past - I wrote the dual spec support for Power Auras Classic. At the time it was available as an alternative download, but it has since been integrated into the main line. Be careful not to step on the developers/maintainers toes (in the case of Power Auras when asked the maintainer preferred it to be hosted on wowinterface rather than on my website for example) - so ask before you do something or at least before distributing it!

Make use of third-party libraries
There are a few about - but the main one I use is Ace (which if you've ever browsed through your add-on directory you'll probably see multiple copies of... it is widely used). If you are just wearing your L plates then use them. Other add-on developers might tell you to avoid them - because they do add an overhead - but they are a great place to start and can do a lot of the leg work for you - which if you find performance issues (or just so desire it) you can always replace the library bindings with your own implementation later.

Don't start with fancy graphics
One of the main things I've had issues with when developing my add-ons is that the UI side of things is a bit mysterious. Tools do exist to help with working with them (I've played with WoW Addon Studio and found it has some stability issues - that may be a Windows 7 thing though). Start with something that doesn't require much in terms of UI and go from there - chat commands are easy to work with! What you can see to the right is one of my dodgy efforts at UI in MTarget - that is supposed to be a drop-down menu (but you can see my newly dinged level 80 hunter in the background I might add).

Use the Source Luke
The one major downsides of add-on development is a lack of good documentation and tutorials to go along side it. There are helpful forums around (the forums on for example) and you can find smatterings of tutorials on wowwiki but you are likely to need to look at the source code to work out different things or get third party libraries to work. Thankfully the source is available for everything you are working with. Blizzard is not happy with the use of obfuscated code, and so it is rare to see an add-on with code that is hard to read. So if you want to know how to do something, or integrate with a library you are most likely going to have to read and understand someone else's code.

The source for the Blizzard add-ons are available over at which I've found to be really useful especially when trying to integrate with standard UI functions.

The following is a list of resources I've made use of - feel free to add more in the comment too!
  1. wowwiki API: World of Warcraft API documentation - this is a (usually) up-to-date copy of the API documentation that gets posted on the official forums.
  2. WoW Ace: a sourceforge for WoW Add-on development - projects hosted here automatically end up on Also there are numerous libraries to work with and the forums are helpful too.
  3. wow compares: the source for the Blizzard add-ons
  4. WoW Addon Studio: a studio for developing UI components
  5. World of Warcraft Programming: a book and website all about programming for WoW. I haven't read the book but have made use of the references at times - but the names behind the book are a number of the big names in WoW Addons.
  6. Lua: The official Lua site - documentation, and code snippets can be found here

Edited to add the reference to World of Warcraft Programming - as pointed out on the Twisted Nether podcast (thanks for the plug!).


    1. SQIAR ( is a leading global consultancy which provides innovative business intelligence services to small and medium size (SMEs) businesses. Our agile approach provides organizations with breakthrough insights and powerful data visualizations to rapidly analyse multiple aspects of their business in perspectives that matter most.