Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: newwaveburritos on Thu 20/08/2020 21:29:25

Title: Implementing text parser in dialog
Post by: newwaveburritos on Thu 20/08/2020 21:29:25
So, I see there is an option to use the text parser as a feature of dialog.  I'd like to use it but I can't understand how exactly to make it function.  First things first make sure to add the word to the parser list.  TNext from the manual:

"If the text parser is enabled for this dialog and the player types something into it rather than selecting an option, the special value DIALOG_PARSER_SELECTED will be returned, and AGS will have automatically called Parser.ParseText with the player's text. Therefore, you can call Parser.Said to process it."

Okay, so far so good.  So far most of what I need is handled automatically.  I look up Parser.Said:

Code (ags) Select

String input = txtParserInput.Text; //the "String input" is declaring that the input it's looking for is a string value and will be the word entered in the parser.
Parser.ParseText(input);
if (Parser.Said("load")) { //or in my case "pop"
  txtParserInput.Text = ""; //this clears the text box
  RestoreGameDialog(); //This is the function it runs in my case I probably want to do something something like dSpecialDialogAboutPop.Start();
}


Now, I know all this stuff needs to go somewhere specific to work but what I can't figure out is where it belongs and the places I have tried return an "undefined symbol 'txtParserInput'" Thanks for the help.  Using AGS has been a fun experience.


Title: Re: Implementing text parser in dialog
Post by: Khris on Mon 24/08/2020 08:44:30
For the dialog parser you don't need the txtParserInput stuff, which refers to a GUI textbox.

All you need is to find/create the dialog_request function in the global script, and use something like:

Code (ags) Select
function dialog_request(int dID)
{
  if (dID == dDialog1.ID) {
    if (Parser.Said("apple")) Display("orange");
  }
}


(When the player presses enter in dialog 5's parser box, AGS calls Parser.ParseText() for you passing the content, then calls dialog_request(5); for you. This function is deprecated otherwise since we can put regular script commands in dialog scripts now, but you do need it for the dialog parser stuff.)

The section of the manual you're referring to suggests you aren't using the standard Dialog.Start() though; in case you do want to use Dialog.DisplayOptions(), use the example code from the manual for that command, then simply call Parse.Said().
Title: Re: Implementing text parser in dialog
Post by: newwaveburritos on Mon 24/08/2020 21:48:57
Okay, that's got it working great.  I was definitely overthinking the whole thing.  I'm just using the regular dialog system and I wanted to use the parser because I think it gives the player some agency in which questions they wish to ask. 

But just to make sure I understand how it works that piece of code you wrote will display "orange" if the player types "apple" into the parser box in Dialog 1.  If I wanted to display "pomegranate" when the player types "tangerine" into the text box in Dialog 2 I would use this code:

Code (ags) Select
function dialog_request(int dID)
{

  if (dID == dDialog1.ID) {
    if (Parser.Said("apple")) Display("orange");
  }
   if (dID == dDialog2.ID){
     if(Parser.Said("tangerine")) Display("pomegranate");
  }
}


So, if you want the ability for the parser to answer a bunch of words you could feasibly have a long line of if statements in there, right?  Thanks so much for your help.

Title: Re: Implementing text parser in dialog
Post by: Khris on Mon 24/08/2020 23:30:45
Yes, exactly.