Thread Tools Display Modes
04-08-10, 10:58 AM   #1
upyursh
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 32
Which slash command was run

What I would like is to be able to have multiple slash commands registered in my addon but then be able to identify which one was executed.

Code:
Addon:RegisterChatCommand( "slasha" , "SlashFunction" )
Addon:RegisterChatCommand( "slashb" , "SlashFunction" )
then when in my SlashFunction function id like to be able to do something like;

Code:
function ProEmote:SlashFunction()

	local slash = MySlash()
        print("You typed " .. slash);
	
end
I know i could use inputs instead and have a single slash command but i'd like it this way if possible

Any ideas how to know what the slash command was that was typed?

Upy
  Reply With Quote
04-08-10, 11:15 AM   #2
Recluse
A Cliff Giant
 
Recluse's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 70
Not sure how to do it with Ace (I think that's what you're using?), but something like this should work...
lua Code:
  1. -- Using ... in case you need args as well. If not, you can remove them.
  2.  
  3. local function SlashHandler(slash, ...)
  4.     print("Used slash command:", slash)
  5. end
  6.  
  7. SLASH_PROEMOTE_FOO1 = "/foo"
  8. SlashCmdList["PROEMOTE_FOO"] = function(...) SlashHandler("foo", ...) end
  9. SLASH_PROEMOTE_BAR1 = "/bar"
  10. SlashCmdList["PROEMOTE_BAR"] = function(...) SlashHandler("bar", ...) end
  11. SLASH_PROEMOTE_BAR1 = "/baz"
  12. SlashCmdList["PROEMOTE_BAZ"] = function(...) SlashHandler("baz", ...) end
__________________
We'd be together, but only diamonds last forever...
  Reply With Quote
04-08-10, 11:16 AM   #3
Fodaro
A Cyclonian
 
Fodaro's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2008
Posts: 42
Well, the way I'd do it is something like this:
Code:
SLASH_MYFIRSTHANDLER1 = "/slash1"
SLASH_MYSECONDHANDLER1 = "/slash1"

SlashCmdList["MYFIRSTHANDLER"] = function()
  HandleSlash(1)
end

SlashCmdList["MYSECONDHANDLER"] = function()
  HandleSlash(2)
end

function HandleSlash(cmdNumber)
  DEFAULT_CHAT_FRAME:AddMessage("You used slash command " .. cmdNumber)
end
__________________
Fodaro
(Main: Fodaro-Bronzebeard (EU))
Author of CharNote and Consolid8
  Reply With Quote
04-08-10, 11:37 AM   #4
Saiket
A Chromatic Dragonspawn
 
Saiket's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 154
Originally Posted by upyursh View Post
Code:
Addon:RegisterChatCommand( "slasha" , "SlashFunction" )
Addon:RegisterChatCommand( "slashb" , "SlashFunction" )
then when in my SlashFunction function id like to be able to do something like;

Code:
function ProEmote:SlashFunction()

	local slash = MySlash()
        print("You typed " .. slash);
	
end

Code:
local function RegisterChatCommand ( Slash )
    Addon:RegisterChatCommand( Slash, function ()
        print( "You typed " .. Slash )
    end )
end

RegisterChatCommand( "slasha" )
RegisterChatCommand( "slashb" )
Note: Drycoded; I don't know if Ace's RegisterChatCommand accepts functions instead of method names, but it probably does.
  Reply With Quote
04-19-10, 10:39 AM   #5
upyursh
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 32
Code:
local function RegisterChatCommand ( Slash )
    Addon:RegisterChatCommand( Slash, function ()
        print( "You typed " .. Slash )
    end )
end

RegisterChatCommand( "slasha" )
RegisterChatCommand( "slashb" )
this worked great! thanks!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Which slash command was run


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off