Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: QuixoticNeutral on Wed 22/01/2014 00:48:00

Title: Accepting coordinates with the text parser?
Post by: QuixoticNeutral on Wed 22/01/2014 00:48:00
Hey all. :)

Apologies if this has already been answered. I've tried looking in the manual and googling, but haven't been able to find an answer for this:

For my game I'd like the player to type in some coordinates for a simple "Please tell me where on the map <macguffin> is." type puzzle.

For illustration the code looks like this:
Code (ags) Select

if (Parser.Said("1,1,1")) {
    Display("You gave the correct coordinate!");
  }


The problem is, the commas are being read by the engine to treat each number as a separate "word", which is giving me errors.

Is there a way to make the parser accept coordinates seperated by commas, or do I need to work around this?

Thanks,
Title: Re: Accepting coordinates with the text parser?
Post by: monkey0506 on Wed 22/01/2014 03:40:53
AFAIK, there's no way to set the parser's delimiters it uses for separating words from each other, but you could work around it by simply using String.Replace before calling Parser.ParseText:

Code (ags) Select
String command = txtParser.Text;
if (command == null) command = "";
command = command.Replace(",", "PARSERCOMMA");
Parser.ParseText(command);
/// ...
String text = "1,1,1";
text = text.Replace(",", "PARSERCOMMA");
if (Parser.Said(text)) { }


In the parser set-up (in the editor) you'll have to substitute commas with "PARSERCOMMA" (or whatever replacement string you choose to use instead).




Alternatively to that (and quite probably the better choice, honestly), you could just parse the coordinates individually as three separate words.
Title: Re: Accepting coordinates with the text parser?
Post by: Gilbert on Wed 22/01/2014 05:24:30
Or, just interpret the String obtained from the parser text with String functions instead of parser functions. This may involve even more scripting though.
Title: Re: Accepting coordinates with the text parser?
Post by: Ghost on Wed 22/01/2014 15:43:32
Quote from: monkey_05_06 on Wed 22/01/2014 03:40:53
Alternatively to that (and quite probably the better choice, honestly), you could just parse the coordinates individually as three separate words.

From a player's perspective I'd prefer that. (nod)
Title: Re: Accepting coordinates with the text parser?
Post by: QuixoticNeutral on Wed 22/01/2014 23:21:38
Treating each coordinate as a separate word worked perfectly! Thanks for the advice all. :)