Me blogging about random interface topics.
Lesson 1: Creating your first mod
Lets start by creating your first mod. I make all the sourcecode available at my GoogleCode project page under the trunk-folder called blog.
You could checkout my whole project via SVN.
Response is important. Input -> Output. I provided all files needed under the folder myFirstMod.
Download the files (blog attachment) or read them via browser. Optimal would be a LUA editor so you could view and edit them locally.
Where do I have to put the myFirstMod-folder? You need to put this folder under your AddOns folder. The local is:
YOUR_PATH_TO_YOUR_WOW_FOLDER\World of Warcraft\Interface\AddOns
Now lets take a closer look at the files and what they do.
First the toc-File. What is a toc-file? Here is the WoWWiki definition:
AddOn - WoWWiki - Your guide to the World of Warcraft
TOC format - WoWWiki - Your guide to the World of Warcraft
So, if you check the myFirstMod.toc the following lines of code can be found:
## Interface: 31337 ## Author: roth ## Title: myFirstMod ## Notes: The is my first mod. Its simple and can talk. core.lua core2.lua core3.lua
Additionally we define all the lua files that will be called.
Now take a look at the core.lua. What does it?
--say Hello World! DEFAULT_CHAT_FRAME:AddMessage("core.lua: Hello World!")
Ok, now lets take a look at the core2.lua.
-- Hello World function local function am(text) DEFAULT_CHAT_FRAME:AddMessage(text) end -- Call the Hello World function am("core2.lua: Hello World!")
Under the function is the call, we call the function with the string "core2.lua: Hello World!". This string is parsed into the variable "text" of the function "am" and then used for the chat output.
A function is called local if its only known to this specific lua file that defines it. Global functions can be called by any lua file around. To make a funtion global and not local, just don't use the prefix "local " infront of the function
Code will be read from top to bottom so the function call must be always below the definition of the function, otherwise the function is unknown.
So let's step further and let's look at the core3.lua
-- Hello world function local function am(text) DEFAULT_CHAT_FRAME:AddMessage(text) end -- Create a local variable of the type Frame local a = CreateFrame("Frame") -- Register a Event on that Frame a:RegisterEvent("PLAYER_LOGIN") -- Set a script that will be run on a given Event a:SetScript("OnEvent", function(self,event) -- Unregister the Event, so that I will only be called once self:UnregisterEvent(event) -- Unset the Script self:SetScript("OnEvent", nil) -- Call the Hello World function am("core3.lua: Hello World!") end)
We can then register a Event on that frame "a" and set up a script that will be run upon "OnEvent" is returned. If we get a result some variables are delivered back. This will be "the frame who called this" (self), "the event return" (event) and some other arguments, mostly knows as "arg1,..." or "...".
What we are doing next is, we only want WoW to use this script once, so we unregister the Event and we unset the script.
At last we do the function call.
So what this addon does is: It will print out 3 lines of "Hello World!" into the chat.
Remember Bob Ross: Its not important what it does, its important what you can do with the information learned by making it happen.
Total Comments 1
Total Trackbacks 0
Recent Blog Entries by zork
- How to handle SetBackdrop and do 1px stuff in just one call (10/26/10)
- Bringing the WOW to your interface (09/21/10)
- oUF_Simple - oUF 1.4 tutorial layout (06/29/10)
- How to create an outer glow by using SetBackdrop (12/09/09)
- Make textures rotate without the need of onUpdate (10/26/09)