WoW:USERAPI SlashCmdList AddSlashCommand: Difference between revisions
Jump to navigation
Jump to search
m (Fixed 2 spelling errors.) |
mNo edit summary |
||
| Line 1: | Line 1: | ||
{{userfunc}} | {{userfunc}} | ||
Add slash commands. | Add slash commands. | ||
SlashCmdList_AddSlashCommand(name, func, ...) | SlashCmdList_AddSlashCommand(name, func, ...) | ||
| Line 24: | Line 23: | ||
SLASH_MYADDON_SLASHCMD2 = '/ma' | SLASH_MYADDON_SLASHCMD2 = '/ma' | ||
==Code== | == Code == | ||
<pre>function SlashCmdList_AddSlashCommand(name, func, ...) | <pre>function SlashCmdList_AddSlashCommand(name, func, ...) | ||
SlashCmdList[name] = func | SlashCmdList[name] = func | ||
| Line 36: | Line 35: | ||
end | end | ||
end</pre> | end</pre> | ||
Revision as of 07:18, 18 May 2020
This page documents a user-defined function that you can copy and paste into your addon. Replace PREFIX with your addon or lib prefix to avoid conflicts between different versions of these functions.
Add slash commands.
SlashCmdList_AddSlashCommand(name, func, ...)
Function Parameters
Arguments
- name
- Unique identifier (e.g. MYADDON_SLASHCMD)
- func
- The function (variable or actual function)
- ...
- A list of commands with or without the leading slash
Returns
- nil
Example
The following snippets do the same thing.
SlashCmdList_AddSlashCommand('MYADDON_SLASHCMD', function(msg)
DEFAULT_CHAT_FRAME:AddMessage(msg or 'nil')
end, 'myaddon', 'ma')
SlashCmdList['MYADDON_SLASHCMD'] = function(msg)
DEFAULT_CHAT_FRAME:AddMessage(msg or 'nil')
end
SLASH_MYADDON_SLASHCMD1 = '/myaddon'
SLASH_MYADDON_SLASHCMD2 = '/ma'
Code
function SlashCmdList_AddSlashCommand(name, func, ...)
SlashCmdList[name] = func
local command = ''
for i = 1, select('#', ...) do
command = select(i, ...)
if strsub(command, 1, 1) ~= '/' then
command = '/' .. command
end
_G['SLASH_'..name..i] = command
end
end