0

Okay so basically i made a chat room and i want to add commands to it. I would like to know how can i get the words of the string for example... if someone types /kick user, i would like for it to recognize "/kick" and then run a function to pass the string "user"

Example

private function kickUser(user:String):void{
kick(user);  //got the user from the /kick user 
}

If anyone can help me with this please let me know :( thanks in advance

1

1 Answer 1

3
var fullCommand : String = "/kick Frank";
var parts : Array = command.split( " " );
var command : String = parts[ 0 ];
var target : String = parts[ 1 ];

switch( command )
{
case "/kick":
{
trace( "I am going to kick: " + target );
break;
}

case "/ban":
{
trace( "I am going to ban the face off: " + target );
break;
}

default:
{
trace( "Undefined command." );
break;
}
}
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks a lot this worked perfectly just did a typo on var fullCommand its suppose to be var command XD but i got the idea it works thanks
This is a good answer, but it'll only work if the phrase after the command is just one word.
@GiorgiAlvarez Well you only need one word, no? I can extend the extraction function if you give me more details on possible commands and parameters. Till then, I would appreciate if you accept the answer.
@Discipol thanks but i found out how to get all the strings in the parts like so... 'var st:String = ""for(var i:int=1;i<parts.length;i++){st += parts[i]+" "}'
And your string will have an empty space at the end. Do this: var short : Array = []; for(var i:int=1;i<parts.length;i++)short.push(parts[i]); and then you trace( short.join( " " );

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.