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 wow.gedsguides.com'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:


<Script>
 message("Ged's Guide to World of Warcraft!!");
</Script>

to a ggwmain.xml that said:


<Script file="ggwmain.lua"/>
<Script>
 GGW_SayHello();
</Script>

plus a ggwmain.lua that contained:


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

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!

No comments:

Post a Comment