[embed=425,349]
How would I use String.Contains with a Text Parser?
For example if the player types in "Hello My name is John", I want it to check if the it contains "Hello" and then Display "Hello"
[/embed]
You would use String.IndexOf (String needle);
Eg:
String input = "Hello World";
if (input.IndexOf("hello") != -1)
Display ("Hello!");
else
Display ("Input does not contain hello.");
Edit: Then again, if you're using a text parser you wouldn't need to use IndexOf, you just use Parser.ParseText.
Eg:
String input = Game.InputBox ("Enter Text:");
Parser.ParseText (input);
if (Parser.Said("hello"))
Display ("Hello!");
else
Display ("Input does not contain Hello.");
This is of course assuming "Hello" isn't an ignored word :D
I guess that wasn't the best example since I want it so If the player types something before "Hello" such as "Also, let me just say hello first".
Since you must feed the text typed by the player into the parser manually, what's keeping you from using String.IndexOf first?
String input = txtParserInput.Text;
// first, do some manual parsing
if (input.indexOf("hello") >= 0) {
// input contains "hello"
...
return; // exit
}
// now, AGS parsing
Parser.ParseText(input);
if (Parser.Said("...")) ...
What if the player says something that contains the word 'hello' but does not necessarily warrant a greeting in return.
For Example:
"Hello, My name is John."
"Hello."
"I love Hello Kitty."
"Hello"
"No, I already said hello to you."
"Hello"
"Grrr, Goodbye you stupid Parser!"
"Goodbye *trolololol*"
:D