Thread Tools Display Modes
07-22-10, 09:24 AM   #1
Vardelm
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 15
help tokenizing slash command args

I need some help creating a slash command that uses 4 arguments. I want the command to look something like this:

/setcoe Searing Totem, Stoneclaw Totem, Healing Stream Totem, Grounding Totem


The idea here is to pass these arguments into a function that will set Call of Elements to use these totems. I already have that function written, so I think I'm OK there. I just need to pass some values to it so I can test it.

Here's the code for the slash command I've been working on thus far:

Code:
----------------------------------------------------------------------------
SLASH_TFSETCOE1 = "/setcoe"
function TF_SetCallOfElements(args)
	
	fireTotem, earthTotem, waterTotem, airTotem = strmatch(args, "%s(%a+),%s(%a+),%s(%a+),%s(%a+),%s", 1)
	
	print("Fire totem is " .. tostring(fireTotem) )
	print("Earth totem is " .. earthTotem)
	print("Water totem is " .. waterTotem)
	print("Air totem is " .. airTotem)
	
	TF_SetCall("Call of Elements", fireTotem, earthTotem, waterTotem, airTotem)
end
SlashCmdList["TFSETCOE"] = TF_SetCallOfElements
----------------------------------------------------------------------------
The line where I'm doing the pattern matching w/ strmatch() is pretty obviously incorrect at the moment. I think that's the line I need help with. The print() lines are in there just for testing. When I use the /setcoe command in a macro in game, all I get out right now is "Fire totem is nil" in my chat, so it seems that the slash command itself is working, but I'm not parsing the arguments correctly.

Help?
  Reply With Quote
07-22-10, 10:24 AM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,929
This is how I deal with all my slash commands but for your purposes it may need a change due to the multiple word statements.

Code:
local function SlashCommands(msg)
  local args = {};
  for word in string.gmatch(msg,"[^%s]+") do
    table.insert(args,word);
  end
Try that and see what args[1] to args[#args] displays for you. It might be that you will need to add the "Totem" part of the name yourself but for localisation it may not be ideal. I haven't quite got the understanding of the gmatch statement down yet but I know this works with single word arguments.

Code:
for idx = 1,#args do
  print(args[idx])
end
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
07-22-10, 01:15 PM   #3
Saiket
A Chromatic Dragonspawn
 
Saiket's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 154
Originally Posted by Xrystal View Post
Code:
local function SlashCommands(msg)
  local args = {};
  for word in string.gmatch(msg,"[^%s]+") do
    table.insert(args,word);
  end

If you modify that gmatch pattern just slightly, it can catch whole totem names:
Code:
for word in string.gmatch(msg,"%s*([^,]*[^%s,])%s*") do

Last edited by Saiket : 07-22-10 at 01:21 PM. Reason: Oops, greedy * quantifier was eating trailing spaces.
  Reply With Quote
07-22-10, 01:39 PM   #4
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,929
Ooh, cool. Thanks Saiket .. *copies to text file for future reference*
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » help tokenizing slash command args


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