Subj : Multiuser chat room
To   : All
From : Ice
Date : Thu Jun 09 2011 04:15 pm

so i want to make a multiplayer "mud" game, and was gonna use tele-arena as my
model, since i rewrote it form worldgroup in C i figured i would make a
synchronet port, that gave me 2 options, C or JS, and since i never played
with JS before i took on a learning project :)

anyhow, to better aid myself i broke the project into steps, first playing
with the ini databasing which i think i pretty much got the hang of, and now
im working on parsing my input routines.

here's what i got thus far:

while(1)
{
   var cmd = console.getstr().toLowerCase();

   if((cmd=="exit") || (cmd=="x")) exit();
   else
   {
      console.writeln(format("You typed: %s",cmd));
      console.crlf();
      console.print(":");
   }
}

while that does work for single word commands i wanted to better learn how to
parse it for multiple character commands.

so like if i wanted to whisper to a user like "whisper <user> <message>"

in C i would go:

if((argc==3) && (!stricmp(argv[0],"whisper")))
{
whisper(argv[1],argv[2]);
}

can anyone point me in the direction for a better formula to grab
pieces of the text and break it into subparts like above?

i tried this way:

var cmd = console.getstr().toLowerCase();

console.writeln(format("You typed: %s",cmd));

var parsed = cmd.split(" ",3);

console.writeln(format("I parsed it to: %s %s %s",parsed[0],
                                                 parsed[1],
                                                 parsed[2]));

which did seem to work but just seemed like a hard way to do something easier.
any thoughts?

---
� Synchronet � Vertrauen � Home of Synchronet � telnet://vert.synchro.net