WoW:Creating a slash command: Difference between revisions

m
Robot: converting/fixing HTML
m (Robot: converting/fixing HTML)
Line 42: Line 42:


* The key of each entry is the <CommandId>. It should be the unique name of your Addon.
* The key of each entry is the <CommandId>. It should be the unique name of your Addon.
* The parser then examines <b>SLASH_<i>&lt;CommandId&gt;</i>1</b>, <b>SLASH_<i>&lt;CommandId&gt;</i>2</b>, ... and so on, until it either finds a match, or gets a nil value (undefined) on the next <b>SLASH_<i>&lt;CommandId&gt;</i><i>&lt;Number&gt;</i></b>.
* The parser then examines '''SLASH_''&lt;CommandId&gt;''1''', '''SLASH_''&lt;CommandId&gt;''2''', ... and so on, until it either finds a match, or gets a nil value (undefined) on the next '''SLASH_''&lt;CommandId&gt;''''&lt;Number&gt;'''''.
* If there was a hit, then the function value of <b>SlashCmdList["<i>&lt;CommandId&gt;</i>"]</b> is invoked, with the rest of the command line as its single parameter
* If there was a hit, then the function value of '''SlashCmdList["''&lt;CommandId&gt;''"]''' is invoked, with the rest of the command line as its single parameter


* Special 'built in' slash commands for chat are handled first.
* Special 'built in' slash commands for chat are handled first.
* The chat handler then iterates over the contents of the global table <b>SlashCmdList</b>
* The chat handler then iterates over the contents of the global table '''SlashCmdList'''
* Otherwise, the next command is searched until a match is found or the list is exhausted.
* Otherwise, the next command is searched until a match is found or the list is exhausted.


Line 53: Line 53:
* Command ID's are generally all caps, with underscores if necessary.
* Command ID's are generally all caps, with underscores if necessary.
* Pick a command ID that's going to be unique to your addon, a common convention is ADDONNAME_COMMANDNAME, or if you just have one, then ADDONNAME (Where ADDONNAME is the name of your addon).
* Pick a command ID that's going to be unique to your addon, a common convention is ADDONNAME_COMMANDNAME, or if you just have one, then ADDONNAME (Where ADDONNAME is the name of your addon).
* The actual <b>SLASH_<i>&lt;CommandId&gt;</i><i>&lt;Number&gt;</i></b> values should be localizable if you plan on your addon being translated, but the command ID will remain the same.
* The actual '''SLASH_''&lt;CommandId&gt;''''&lt;Number&gt;''''' values should be localizable if you plan on your addon being translated, but the command ID will remain the same.
* Be prudent about how many aliases you make for your command, and try and pick something that's unlikely to collide with someone else's.
* Be prudent about how many aliases you make for your command, and try and pick something that's unlikely to collide with someone else's.
[[Category: HOWTOs|Create a Slash Command]]
[[Category: HOWTOs|Create a Slash Command]]
Anonymous user