These forums are in read-only mode. Please see this news post for more information.

New forums can be found here

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

Thread Tools
Old 01-18-2012   #1
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:

/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
Senior Member
Lombra's Avatar
Join Date: Jan 2006
Posts: 431
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)
	local cmd, arg = msg:match("%s*(%S+)%s+(%S+)")
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!
Lombra is offline   Reply With Quote

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 03:28 PM.