Accepting coordinates with the text parser?

Started by QuixoticNeutral, Wed 22/01/2014 00:48:00

Previous topic - Next topic

QuixoticNeutral

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

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,

monkey0506

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
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.

Gilbert

Or, just interpret the String obtained from the parser text with String functions instead of parser functions. This may involve even more scripting though.

Ghost

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)

QuixoticNeutral

Treating each coordinate as a separate word worked perfectly! Thanks for the advice all. :)

SMF spam blocked by CleanTalk