Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
WoW
Talk
English
Views
Read
Edit
History
More
Search
Navigation
Home
Random page
Help using wiki
Editions
for WoW
for WildStar
for Solar2D
Documentation
for WoW
for WildStar
Reference
WoW
⦁ FrameXML
⦁ AddOns
⦁ API
⦁ WoW Lua
WildStar
⦁ AddOns
⦁ API
⦁ WildStar Lua
Engine
Tools
What links here
Related changes
Special pages
Page information
Site
Recent Changes
Editing
WoW:Creating a slash command
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Parsing Arguments == If the user types '/yourcmd someargs' into chat, the function handling '/yourcmd' is passed 'someargs' as the first argument we have been naming 'msg', with the second argument as the chat edit box widget. Your handler function can then choose to act on that argument string. For simple slash commands, comparisons to pre-determined strings may be sufficient. Suppose we wanted to modify the "Hello, World!" example above to display a different string if the command was passed an argument, say "/hiw bye". local function MyAddonCommands(msg, editbox) if msg == 'bye' then print('Goodbye, World!') else print("Hello, World!") end end SLASH_HELLOWORLD1, SLASH_HELLOWORLD2 = '/hiw', '/hellow' SlashCmdList["HELLOWORLD"] = MyAddonCommands -- add /hiw and /hellow to command list Here is a more complex slash command example that is able to process arguments for commands that uses Lua [[Pattern matching]] to parse the arguments string: local function MyAddonCommands(msg, editbox) -- pattern matching that skips leading whitespace and whitespace between cmd and args -- any whitespace at end of args is retained local _, _, cmd, args = string.find(msg, "%s?(%w+)%s?(.*)") if cmd == "add" and args ~= "" then print("adding " .. args) -- Handle adding of the contents of rest... to something. elseif cmd == "remove" and args ~= "" then print("removing " .. args) -- Handle removing of the contents of rest... to something. else -- If not handled above, display some sort of help message print("Syntax: /hellow (add|remove) someIdentifier"); end end SLASH_HELLOWORLD1, SLASH_HELLOWORLD2 = '/hiw', '/hellow' SlashCmdList["HELLOWORLD"] = MyAddonCommands -- add /hiw and /hellow to command list
Summary:
Please note that all contributions to AddOn Studio are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
AddOn Studio Wiki:Copyrights
for details).
Submissions must be written by you, or copied from a public domain or similar free resource (see
AddOn Studio Wiki:Copyrights
for details).
Cancel
Editing help
(opens in new window)