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"))
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
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
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
}
Ayuh, that's what I was kinda hinting at. ::)
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'
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).
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?
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...
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.
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 */ }