WoW:USERAPI RunSlashCmd: Difference between revisions

m
no edit summary
No edit summary
mNo edit summary
Line 1: Line 1:
{{userfunc}}
The following snippet provides a global function RunSlashCmd that can be used to execute an arbitrary slash command (i.e. "/myaddon hi").
The following snippet provides a global function RunSlashCmd that can be used to execute an arbitrary slash command (i.e. "/myaddon hi").
  local _G = _G
  local _G = _G
Line 24: Line 26:
       i = i + 1
       i = i + 1
   end
   end
  end  
  end


=== Usage ===
=== Usage ===
Line 32: Line 34:


== Alternative ==
== Alternative ==
Another method to accomplish the same effect is to insert the command into an editbox and send the command. Note that it's usually better to do this with your own EditBox to avoid taint or conflicts with user input into the default editbox.
Another method to accomplish the same effect is to insert the command into an editbox and send the command. Note that it's usually better to do this with your own EditBox to avoid taint or conflicts with user input into the default editbox.


  -- Create our editbox (may not need a name, untested)
  -- Create our editbox (may not need a name, untested)
Line 40: Line 42:
  ChatEdit_SendText(editbox)
  ChatEdit_SendText(editbox)


However as of 3.3.5 you must set the chatFrame variable on your editbox before the OnLoad function runs. So if you want to use the above code you need to create the frame in XML or create a template and then use that template to create the frame.
However as of 3.3.5 you must set the chatFrame variable on your editbox before the OnLoad function runs. So if you want to use the above code you need to create the frame in XML or create a template and then use that template to create the frame.


  <EditBox name="MyAddOnEditBoxTemplate" inherits="ChatFrameEditBoxTemplate" virtual="true">
  <EditBox name="MyAddOnEditBoxTemplate" inherits="ChatFrameEditBoxTemplate" virtual="true">
Line 57: Line 59:
  editbox:SetText("/command here")  
  editbox:SetText("/command here")  
  ChatEdit_SendText(editbox)
  ChatEdit_SendText(editbox)
[[Category:User defined functions]]
[[Category:User defined functions]]