Adding the "it" feature to the parser [SOLVED (it's now good enough)]

Started by Laukku, Fri 08/08/2008 19:41:36

Previous topic - Next topic

Laukku

After finding out, how primitive the Text Parser v2.0 template is, I have been trying to improve it. I've been successful so far; I've added a SCI-style pop-up parser GUI that turns on when you start typing, a text-based inventory list, a NoMatch() function etc. It's now almost at the level of the old Sierra SCI parser games. Almost.

The Sierra parser had a feature that made it possible to write look at the apple, then take it, and the parser would still understand it. This was too hard for me to pull off with AGS, so gave up and posted this thread.
I'm thinking that basically, you would have to do something like this:


if the command does not contain the word "it", save the last word as a string and continue normally
if the command does contain the word "it", replace it by the string* and parse it


The hard part is retrieving the last word of the command. Any hints?
NOTE: I'm using 2.72 for some reason.


*or have "it" as a "ignore" word and put the string at the end of the command. Does not work for throw it at the bird, though.
You are standing in an open field west of a white house, with a boarded front door.
>WIN GAME
Congratulations! You just won! You got 0 out of 500 points.

Pumaman

If all your parser commands are of the VERB + NOUN combination, you could save the last word of what the player typed, and then do a string replace on "it" the next time round.

To find the last word in the string, you can use the String.Chars property to check for a space, something like:

int i = myText.Length - 1;
while (i >= 0)
{
  if (myText.Chars[ i ] == ' ')
  {
     lastWord = myText.Substring(i + 1, myText.Length - (i + 1));
  }
  i--;
}

Laukku

#2
Thanks  ;D I thought of that, but decided to ask for possible alternative solutions. I'll try if it works.

EDIT: Weird. AGS seems to think that neither .Contains nor .Length are public members of 'string'. I can swear they are documented in the manual.
You are standing in an open field west of a white house, with a boarded front door.
>WIN GAME
Congratulations! You just won! You got 0 out of 500 points.

RickJ

Well the obvious thing (at least to me) is to have the "Look at apple" handler set a String variable ( String it_pronoun; for example) to "apple".  Then when "it" is encountered in the next input replace "it" with the contents of the variable it_pronoun. 

In a generalized solution there would probably two static String variables  ParserNoun and ParserPronoun, which would get populated by a call to a parser function made from the "Look at apple" event handler.

String ParserNoun, ParserPronoun. 

So in the lookat event handler you would have something like this ...

function lookat_Apple() {
   ParserNoun("Apple", "it");
   player.Say("It's a big juicy apple,..");
}


Pumaman

Quote from: Laukku on Fri 08/08/2008 20:06:01
EDIT: Weird. AGS seems to think that neither .Contains nor .Length are public members of 'string'. I can swear they are documented in the manual.

Make sure you use 'String', with a capital S. The 'string' type is obsolete and doens't have these features.

Laukku

#5
Quote from: Pumaman on Fri 08/08/2008 20:57:32
Quote from: Laukku on Fri 08/08/2008 20:06:01
EDIT: Weird. AGS seems to think that neither .Contains nor .Length are public members of 'string'. I can swear they are documented in the manual.

Make sure you use 'String', with a capital S. The 'string' type is obsolete and doens't have these features.


But I never wrote "string" anywhere! The

   int i = input.Length -1;

line was one that gave the error message.

EDIT: Besides, "Enforce new-style Strings" is unchecked.

EDIT2: I checked it, tried to save game: Now it complains "type 'string' is no longer supported". I think I'm starting to solve this by myself  ;D

EDIT3: OK, I got rid of all error messages  ;D ;D ;D

EDIT4:YES!!!!!!!!!!!! ;D ;D ;D ;D ;D ;D ;D ;D ;D Got it working!!!!!!!!!

EDIT5: Where are my manners? Thank you! :)
You are standing in an open field west of a white house, with a boarded front door.
>WIN GAME
Congratulations! You just won! You got 0 out of 500 points.

SMF spam blocked by CleanTalk