在开发Addon之前,必须了解其构成。在WoW中,规定Addon由至少三中文件构成:
- toc:指明该Addon适用的客户端API版本,以及Addon包含(和依赖)的文件。
- xml:用于创建UI,指明事件处理脚本(Lua)。在某些情况下,可以不需要Lua文件,而直接将脚本嵌入到<scripts></scripts>标签中。
- lua:实现Addon功能的脚本。
Test.toc文件内容:
## Interface: 20300
## Title: Test Addon
test.lua
test.xml
Test.xml文件内容:## Title: Test Addon
test.lua
test.xml
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/../FrameXML/UI.xsd">
<Frame name = "Test_Frame" hidden="true">
<Scripts>
<OnLoad>Test_load();</OnLoad>
</Scripts>
</Frame>
</Ui>
Test.lua文件内容:<Frame name = "Test_Frame" hidden="true">
<Scripts>
<OnLoad>Test_load();</OnLoad>
</Scripts>
</Frame>
</Ui>
function Test_load()
-- Slash Commands
SLASH_Test1 = "/test";
SlashCmdList["Test"] = Test_commandline;
DEFAULT_CHAT_FRAME:AddMessage("Test AddOn is now loaded!");
end
function Test_commandline(cmd)
local a = gsub(cmd , "(%d+)(%s)(%d+)", "%1");
local b = gsub(cmd , "(%d+)(%s)(%d+)", "%3");
DEFAULT_CHAT_FRAME:AddMessage("a + b ="..a+b);
end
为了运行Addon,需要将上述三个文件放在
客户端安装目录下/Interface/AddOns/Test目录下,然后启动客户端,在聊天框中输入:/test <arg1> <arg2>就可以运行脚本了。截图如下:-- Slash Commands
SLASH_Test1 = "/test";
SlashCmdList["Test"] = Test_commandline;
DEFAULT_CHAT_FRAME:AddMessage("Test AddOn is now loaded!");
end
function Test_commandline(cmd)
local a = gsub(cmd , "(%d+)(%s)(%d+)", "%1");
local b = gsub(cmd , "(%d+)(%s)(%d+)", "%3");
DEFAULT_CHAT_FRAME:AddMessage("a + b ="..a+b);
end
为了运行Addon,需要将上述三个文件放在