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:
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,
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:
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.
Or, just interpret the String obtained from the parser text with String functions instead of parser functions. This may involve even more scripting though.
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)
Treating each coordinate as a separate word worked perfectly! Thanks for the advice all. :)