Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: mkennedy on Fri 29/09/2006 12:55:58

Title: Sugestion - more leniant version of said.
Post by: mkennedy on Fri 29/09/2006 12:55:58
I would like a more leninat version of the function 'said' that rather than checking the whole string the player typed it would only check to see if the typed string contains the desired word. Rather than replace 'said' the function could have a name like spoke.  For example lets say you want to run an interaction if the player uses the object 'beer' on the character 'Homer' you can check this with the code:

if (Parser.Spoke("beer"))  and if (Parser.Spoke("Homer"))

Title: Re: Sugestion - more leniant version of said.
Post by: Rui 'Trovatore' Pires on Fri 29/09/2006 13:42:58
You mean like the functions StrContain (and its 2.7 counterpart), and like "if (Said(anyword beer rol))" stuff?

Edit by strazer: it's <> its

Edit by Trovatore - why thank you, Strazer, I needed the grammar brush-up. ;D
Title: Re: Sugestion - more leniant version of said.
Post by: mkennedy on Fri 29/09/2006 17:42:11
Quote from: Rui "Trovatore" Pires on Fri 29/09/2006 13:42:58
You mean like the functions StrContain (and its 2.7 counterpart), and like "if (Said(anyword beer rol))" stuff?

Yeah, similar to StrContain. This way the player could have typed andy of the following:

Use beer on Homer
Give beer to Homer
Give Homer beer
Beer Homer
Title: Re: Sugestion - more leniant version of said.
Post by: Pumaman on Fri 29/09/2006 19:18:16
Well, if you're not bothered about teh sentence structure and just want to check for particular words, it's just as easy to do it yourself:

if (input.Contains("beer") && input.Contains("Homer")) {
// do something
}
Title: Re: Sugestion - more leniant version of said.
Post by: Rui 'Trovatore' Pires on Sat 30/09/2006 02:32:56
Ayuh, that's what I was kinda hinting at. ::)
Title: Re: Sugestion - more leniant version of said.
Post by: mkennedy on Sun 01/10/2006 05:30:52
Quote from: Pumaman on Fri 29/09/2006 19:18:16
Well, if you're not bothered about teh sentence structure and just want to check for particular words, it's just as easy to do it yourself:

if (input.Contains("beer") && input.Contains("Homer")) {
// do something
}

I seam to be having trouble with the .Contains function. My code is:

  if (interface == 0) {    //starts parsing, including any global commands
    if (button == 0)
    {string forparser,unknownbuffer;
     StrCopy(forparser,"");
     GetTextBoxText(0,0,forparser);
     InterfaceOff(0);
     if (StrComp(forparser,""))
      {ParseText(forparser);
       if (SaidUnknownWord(unknownbuffer))
         Display ("I don't understand the word '%s'.",unknownbuffer);
       else
         SetGlobalInt(6,1); //sends signal to room to contine parsing
counter = 1;
  while (counter < Game.InventoryItemCount) {
if (forparser.Contains(inventory[counter].Name))
player.ActiveInventory = inventory[counter];
counter ++;
}      }
     }
  } // end iface 0

But when I go to save the game I get an error message saying:

.Contains  is not a puclic member of 'string'
Title: Re: Sugestion - more leniant version of said.
Post by: GarageGothic on Sun 01/10/2006 09:19:38
It's because you're using old scripting style with strings rather than Strings. You need to use StrContains instead, or rewrite your code to use Strings (maybe not possible depending on which AGS version you're using).
Title: Re: Sugestion - more leniant version of said.
Post by: mkennedy on Mon 02/10/2006 07:10:52
Quote from: GarageGothic on Sun 01/10/2006 09:19:38
It's because you're using old scripting style with strings rather than Strings. You need to use StrContains instead, or rewrite your code to use Strings (maybe not possible depending on which AGS version you're using).

Thanks for the tip, I'm getting it to work now. Too bad the new String functions don't seam to work on old style string or char variables. Do the new String functions also work with synonyms from the parser list?
Title: Re: Sugestion - more leniant version of said.
Post by: Rui 'Trovatore' Pires on Mon 02/10/2006 10:23:01
No, that's why I also suggested the "if (Said(anyword beer rol))" structure. It might imply a couple more AND/OR statements, but then, so would "if string contains this AND this AND this OR this" and so on...
Title: Re: Sugestion - more leniant version of said.
Post by: mkennedy on Sun 15/10/2006 11:57:39
The problem with that would be if word beer is the 4th or 5th word entered. As far as I know anyword only discards a single word. Thta's primarily why I suggested the more leniant version of said. The main reason for my interest is becuase I am developing a text parser template. So far I've made it so that the game will automaticly run the correct interaction based on what the player typed in.
Title: Re: Sugestion - more leniant version of said.
Post by: monkey0506 on Sun 15/10/2006 20:38:59
I don't know too much about the text parser functions, but could you do something like:

if ((txtParser.Text.Contains("beer ") != -1) && (Said(String.Format("%sbeer rol", txtParser.Text.Substring(0, txtParser.Text.Contains("beer "))))) { /* blah */ }