Go Back   WowAce Forums > General > Lua Code Discussion
Lua Code Discussion You scared? Terrified. Mortified. Petrified. Stupefied... by [coding].

Reply
 
Thread Tools
Old 01-18-2012   #1
moselekm
Newbie
 
Join Date: Oct 2008
Posts: 9
Default Using string.sub and returned text

Not sure how I should have worded the title, it's probably inaccurate.

Either way, I am working on an addon that builds an array of character's names through slash commands.

I want it to basically do this. The addon is called ScrubAway, I want it to add the character's name to the array through this command:

Quote:
/sa add Playersname
And through that it grabs the text added after /sa add and inserts it into the table.

I was thinking: Oh I can use string.sub from the 9th character to the end. However I realized I would require the string for the string.sub function.

Is this possible? To save the string that is placed at that command so that my string sub can run the variable?

Hope this makes sense.

Thanks guys!
moselekm is offline   Reply With Quote
Old 01-18-2012   #2
Lombra
Senior Member
 
Lombra's Avatar
 
Join Date: Jan 2006
Location: Sweden
Posts: 410
Default Re: Using string.sub and returned text

To capture "Playersname", you could do something like this in your slash handler: (the slightly more foolproof way)
Code:
function(msg)
	local cmd, arg = msg:match("%s*(%S+)%s+(%S+)")
	addToArray(arg)
end
The first argument of your slash handler (msg) is what comes after the base slash command + one whitespace character, so "add Playersname", in this case. And in this function, cmd will be "add" and arg "Playersname".
__________________
Grab your sword and fight the Horde!

Shattered Hand-EU
Lombra is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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

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

Forum Jump


All times are GMT. The time now is 04:15 PM.