WoW:Creating a slash command: Difference between revisions

m
→‎Simple Example: Unfinished sentence
No edit summary
m (→‎Simple Example: Unfinished sentence)
Line 1: Line 1:
Basics of supporting a [[slash command]] in your [[AddOn]].
This HOWTO teaches the basics of creating [[slash command|slash commands]] for your [[AddOn]].


== Simple Example ==
== Simple Example ==
Line 9: Line 9:
  end
  end
   
   
In your '''OnLoad function''' of your script, ''or'' in the .lua '''anyplace after the function is defined''', put in the following:
In the '''OnLoad function''' of your script, ''or'' in the .lua '''any place after the function is defined''', put in the following:


  SLASH_MYSCRIPT1 = "/myscript";
  SLASH_MYSCRIPT1 = "/myscript";
Line 15: Line 15:
  SlashCmdList["MYSCRIPT"] = MyScript_Command;
  SlashCmdList["MYSCRIPT"] = MyScript_Command;


'''Note''': The slash command(s) must be defined in an OnLoad Function or after the function has been defined. If the slash command is defined when the function it "points to" (which is <tt>MyScript_Command</tt> in the above script) has not been defined yet, the slash command '''will not work'''.


Note: The slash command(s) must be defined in an OnLoad Function or after the function has been defined.
== Further Examples ==
EX.


OnLoad Function:
'''OnLoad Function:'''


  function addonname_OnLoad()
  function AddonName_OnLoad()
   SlashCmdList["ADDONNAME"] = FunctionToCall;
   SlashCmdList["ADDONNAME"] = FunctionToCall;
   SLASH_ADDONNAME1 = "/slash1";
   SLASH_ADDONNAME1 = "/slash1";
   SLASH_ADDONNAME2 = "/slash2";
   SLASH_ADDONNAME2 = "/slash2";
  end
  end
function AddonName_SlashCmdHandler()
  -- do stuff
end
And in your XML file:
<OnLoad>
  AddonName_OnLoad();
</OnLoad>


After Function Has Been Defined:
The above example will work as long as <tt>AddonName_OnLoad</tt> is called.


  function my_function()
'''After the function has been defined:'''
 
  function MySlashCmdFunction()
  -- Some stuff here
  -- Some stuff here
  end
  end
   SlashCmdList["ADDONNAME"] = FunctionToCall;
   SlashCmdList["ADDONNAME"] = MySlashCmdFunction;
   SLASH_ADDONNAME1 = "/slash1";
   SLASH_ADDONNAME1 = "/slash1";
   SLASH_ADDONNAME2 = "/slash2";
   SLASH_ADDONNAME2 = "/slash2";
Line 53: Line 65:
== Conventions ==
== Conventions ==


* Command ID's are generally all caps, with underscores if necessary.
* Command ID's are generally all caps, with underscores if necessary. These can also contain lowercase characters.
* 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 '''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.
* 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 (including Blizzard's!)


[[Category:AddOns|Create a Slash Command]]
[[Category:AddOns|Create a Slash Command]]
[[Category:HOWTOs|Create a Slash Command]]
[[Category:HOWTOs|Create a Slash Command]]
Anonymous user