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?
That's a pretty common method of JS string parsing. See https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String for
the JS String reference. Synchronet doesn't add any new/different string parsing classes.
Sysop: | Chris Crash |
---|---|
Location: | Huntington Beach, CA. |
Users: | 578 |
Nodes: | 8 (0 / 8) |
Uptime: | 29:18:26 |
Calls: | 10,736 |
Calls today: | 1 |
Files: | 5 |
Messages: | 443,196 |
Posted today: | 1 |