Re: Multiuser chat roomã By: Ice to All on 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?ãã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.ãã digital manããSynchronet "Real Fact" #18:ãThe first Synchronet BBS (Vertrauen) went live in July of 1991 (replacing WWIV).ã---ã þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.netã