<Originally posted on my blog at http://shiftysgoldadventures.blogspo...for-stack.html>
Due to how many people have wanted a modified Auctionator code and i'm not sure on the ability for me to release the addon with the modification without being in trouble from Zirco the original author of the Auctionator.(I have messaged them asking them but yet no reply)
What are we doing?
Hopefully learning something atleast. But at the most you will be adding a button to Auctionators sell interface which in turn will swap Stack size with Amount of auctions. So if you had 20 stacks of 1 hitting the button will make it say 1 stack of 20 instead and then clicking Create auction will proceed to post that 1 stack.
Auctionator - Well this one is obvious
ScitE or Notepadd++ - Although you could use any text editor, i prefer these 2 due to the line numbers which will be needed.
Me - Could be replaced by someone else with knowledge.
DISCLAIMER:BACK UP YOUR WTF AND ADDONS FOLDER BEFORE ATTEMPTING INCASE YOU ACCIDENTALLY MAKE WOW CRY WITH YOUR BAD EDITTING I TAKE NO RESPONSIBILITY FOR ANYTHING YOU DO INSIDE OF YOUR WOW FOLDER
Let's do it?
Ok, to start you will need to open your choice of editing program i will be using ScitE for this but you can follow along with anything(including notepad but enjoy counting lines).
First thing is to go to your addon folder mine is located at "C:\Program Files (x86)\World of Warcraft\Interface\AddOns" Then go to Auctionator folder and you want to open Auctionator.XML and Auctionator.LUA file.
What are these files?
The LUA (Pronounced Loo Ah)file is the main code for an addon, this is where most of the magic happens for addons Lua is a pretty simple programming language that can be used for multiple things, WoW uses it as a language to interpret into WoW.
The XML(Extensible Markup Language) file contains the UI elements for Auctionator. Simple to use, complex to write.
We will add the button into the XML file and the commands the button does in LUA.
Open up the XML file and scroll down to line 697(this is where having line numbers comes into play) and add the code: http://pastebin.com/LAgszsaJ
Let's break it down.
<Button name="Atr_SwitchSizeButton" inherits="UIPanelButtonTemplate" text="Switch Sizes" disabled="false">
This line Creates a button called "Atr_SwitchSizeButton" which can be referenced inside of the LUA file at a later date.
Inherits tells the button to get the same layout data from blizzard own "UIPanelButtonTemplate" which is a basic button that has the red background.
Text is the text to display on the button.
Disabled=true will mean the button is able to be clicked, Disabled = false will make the button grayed out.
<Size><AbsDimension x="150" y="20"/> </Size>
<Size> refrences the size of the button object it can be changed directly by <size x="150" y="20"/> but most developers tend to use absDimension which if i remember right stand's for Absolute Dimension.
<AbsDimension> refrences the absolute dimension of the object, x being width and y being height of the button.
</Size> just closes the object reference. When programming its easy to forget to close a function or object
<Anchors><Anchor point="TOPLEFT"><Offset><AbsDimension x="25" y="-240"/></Offset></Anchor></Anchors>
ahh anchors, Anchors define the core placement of objects on the screen in wow the place they reference is inside of its parent frame. Setting an anchor point to "TOPLEFT" means that by default without positioning the button will sit in the "TOPLEFT" of the Auction house frame.
<Offset> is how much to offset from the Anchor point that was previously stated. x="25" means it moves 25 pixels across and y="-240" will move the button down from the anchor point the reason we use -240 is due to that if we did a straight 240 it will move up instead of down, also if we did -25 it would move in the opposite direction.
<Scripts></Scripts> inside of these lines is where we reference what each command the object can recieve will do. The basic button command <OnClick> is what will happen when someone clicks the button. In our tutorial here we see it references a Function Atr_SwitchSizeButton_OnClick(); which we will talk about when we get into LUA, but for now anything between <OnClick> and </OnClick> can be LUA or should be. For our tutorial you could test this out by replacing the function with "print("Hello, i am running")".
The other parts of the XML section only close objects/frames, typically anything with a preceding "/" will be a closing argument. </End of xml section> :P
Ok, now comes the coding of what the button does.
Open up your Auctionator.lua file and scroll down the very bottom and add this code: http://pastebin.com/EJH8uA9D
You may notice my screen shot has 1 extra line then your code will that is because the "--print(NumOf,StackSize)" was just there to test out if the code was working =]
Breaking it down!
This is a function in lua, basically a function is a block of code that can be run my referencing its name anywhere in the existing addon. You may remember this function from the previous XML section on the <OnClick> command of the button. here is where will be issuing what pressing the button should do.
Basically a function will have 3 constant things, the command "function" which tells that the following is a function. "Name" which is the name we give to the function which in our case is "Atr_SwitchSizeButton_OnClick()" having a good name that describes what the function does is normally good to do. and finally "End" which tells when the function should end, as you can see in our code that is after we switch the numbers.
local NumOf = Atr_Batch_NumAuctions:GetNumber()
local StackSize = Atr_Batch_Stacksize:GetNumber()
These 2 lines are variables. Variables hold different type of data that can be used just by referencing the variable name. These variables reference "Atr_Batch_NumAuctions:GetNumber()" and "Atr_Batch_Stacksize:GetNumber()" which basically references different text boxes inside of our XML we edited. "Atr_Batch_Stacksize" is the frame to reference and ":GetNumber()" is the command to run on the frame. GetNumber() will literally do as it say's, get the number for the frame.
As we just previously saw Atr_Batch_NumAuctions and Atr_Batch_Stacksize are frame name's and what follows is the command to run on that frame which we currently are doing is ":SetNumber(StackSize)" which i am sure if you have gotten this far you know what it does.
Inside the brackets are what we are going to set the Frame to which is our variables previously created.
As you can see what we basically did was add each frames contents into a variable then added the opposite frames variable into each other which in turn switches the stack sizes and amount.
This just tells us that we want to end the function here. if we don't end a function WoW will throw a <EOF> error, which stands for End Of File which typically happens when WoW cant find the end of a file.
Now all you have to do is Save both those files and /reload in game or log on and make sure you have no errors!
I hope this was helpful and in the future if you wish to see more tutorials for addons like this please leave a comment!
If you need any further help please feel free to drop me a message on twitter @shiftywarloc.