WoW:Getting started with writing AddOns (source)
Revision as of 18:21, 20 October 2015
, 20 October 2015→TOC File
| Line 71: | Line 71: | ||
## Interface: {{API LatestInterface}} | ## Interface: {{API LatestInterface}} | ||
## Title : My AddOn | ## Title : My AddOn | ||
## Notes: This AddOn does nothing but display a frame with a button | <nowiki>##</nowiki> Notes: This AddOn does nothing but display a frame with a button | ||
## Author: My Name | <nowiki>##</nowiki> Author: My Name | ||
myAddOn.xml | myAddOn.xml | ||
# This is a comment. Interface: | <nowiki>#</nowiki> This is a comment. Interface: 60200 refers to WoW client version 6.2 | ||
You can read more about what you need or can put in a TOC over at [[The TOC Format]] | You can read more about what you need or can put in a TOC over at [[The TOC Format]] | ||
| Line 101: | Line 101: | ||
== Start Coding! == | == Start Coding! == | ||
Start with the tutorials extracted by the [http://us.blizzard.com/support/article.xml?locale=en_US&articleId=21466 Interface AddOn Kit]. The [[HOWTOs]] here has a ton of great examples to help you learn. Don't be shy to dig through someone else's AddOn for help, just be sure to not steal code, and give credit where credit is due. | Start with the tutorials extracted by the [http://us.blizzard.com/support/article.xml?locale=en_US&articleId=21466 Interface AddOn Kit]. The [[HOWTOs]] here has a ton of great examples to help you learn. Don't be shy to dig through someone else's AddOn for help, just be sure to not steal code, and give credit where credit is due. | ||
Beware Lua functions and variables are globals by default and are directly visible to the other addons. If authors blindly use simple and common names, like: | |||
addonEnabled = true; | |||
function GetArrowsCount() | |||
... | |||
end | |||
an addon will easily conflict with variables of the same name from other addons or from the Blizzard interface. Instead, you should write your addon more like a Lua module: place all the data and functions in a single global table, named after the addon, and use local declarations otherwise (no other globals), like: | |||
MarksmanAddOn = { }; -- about the only global name in the addon | |||
local addonEnabled = true; -- local names are all ok | |||
function MarksmanAddOn:GetArrowsCount() | |||
... -- function is now inside the global table | |||
end | |||
MarksmanAddOn.arrowsCount = MarksmanAddOn:GetArrowsCount() | |||
For large add-ons this can get complicated, and the current version of Lua doesn't offer much to help. Use a full, clear, name for the global table, and assign a shorter name in your .lua files, like: | |||
local mod = MarksmanAddOn; | |||
-- then you can write | |||
mod.arrowsCount = mod:GetArrowsCount() | |||
Other then the global table for the addon, you may still need globals for the saved variables and the addon slash commands (see below) if you have any. | |||
== Slash Commands == | == Slash Commands == | ||