Saturday, 18 February 2006

Addon progress

I'm getting more used to lua, though I still find it a bit odd. It seems to be reasonably orthogonal, which is nice. This means you have ways to indicate default arguments that don't involve hacks to the language. For example, if I want to indicate to a function that its should default to inspecting the currently selected player, npc or mob I can tell it to default to "target" by writing:

function myFunc( unit )

 unit = unit or "target"
 -- more code goes here...


I've managed to get most of the information I want regarding beasts, and very interesting the trawl has been too. The only thing I don't seem to be able to get is the beast's dietary requirements. Now that must be available since the beast lore UI, the stable UI and the pet UI all display it; however it doesn't seem to be referenced anywhere. I've put a question in a forum, maybe I'll get a response from that.

Thursday, 16 February 2006

My first WoW addon

So last night I decided I needed to start addon development. Long-term I want to be able to feed stats to's database (just like the big boys, lol). Short-term, I thought, something that will capture the results of a Beast Lore on a selected beast and write it to a file. It doesn't need a UI: just a function that's callable from a macro will do. Extremely simple, you'd think.

The first step was to read up the tutorials on the web (ouch! they are out of date!) and do a little teensy application that just put up a message box on entry to the game. Which stopped working as soon as I moved the body of the script out of the xml file into the lua file: I kept on getting an error about trying to call a global that was nil. I'd moved from having a ggwmain.xml that said:

 message("Ged's Guide to World of Warcraft!!");

to a ggwmain.xml that said:

<Script file="ggwmain.lua"/>

plus a ggwmain.lua that contained:

function GGW_SayHello()
 message("Ged's Guide to World of Warcraft!!");

I googled the text of the error message, and found dozens of complaints from addon users that their addons had stopped working with the release of patch 1.9 of WoW, but no answers that would indicate a cause except for vague protestations by the addon writers that something must be wrong with the users' installations. Duh!

Assuming that the "global" referred to was the name of the function in the lua file referenced in the xml file, the error message was obviously saying it couldn't find it. Which meant that the lua file probably wasn't being loaded. Hmm, I remembered that the original article had been insistent about its main xml file and its main lua file having filenames identical to that of the addon directory. So my addon being directory being "AddOns/GGW" I changed the xmlfile to "GGW.xml" and the lua file to "GGW.lua", updated the reference to the lua file in the xml file, updated the reference to the xml file in the toc (table of contents) file, quit WoW and relaunched it.

It worked straight away. How very disappointing. Little rules like that are like a red rag to a bull for me: if you have to make the filenames identical, then why is it necessary to specify them? If your main lua file has to be called addonname.lua then shy do you have to specify in the xml file that it's called addonname.lua? If your xml file has to be called addonname.xml then why do you have to specify addonname.xm in the toc file? It's redundant!

So this morning I decided to backtrack and find out where it would break. Firstly I renamed the lua file back to ggwmain.lua and updated the reference in the xml file. Started WoW. It still worked. So it must be the xml file! With trembling hands, I renamed the xml file to prue.xml and updated the toc file. Quit WoW. Restarted it. It still worked!

So now I have no explanation for the original failure. Eek!