Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Ethan D on Sat 25/07/2009 01:13:33

Title: Parser
Post by: Ethan D on Sat 25/07/2009 01:13:33
I'm working on setting up a parser for a game and I want to set it so that The player can just start typing and the GUI will show up, much like Trilby's Notes.  Do I have to set each of the letter keys  individually or is there a way to do it more efficiently? 
Title: Re: Parser
Post by: on Sat 25/07/2009 01:47:23
The on_key_press function() in your global script is called whenever ANY key is pressed, to I'd call the GUI there.
Title: Re: Parser
Post by: Ethan D on Sat 25/07/2009 15:43:31
Im having trouble figuring out how to set the Gui so that if you press enter that acts as the parser. Any ideas?
Title: Re: Parser
Post by: Ethan D on Sat 25/07/2009 15:50:35
So far I have it so when you type in for instance look painting the display comes up before pressing enter which causes it to get stuck there.
Title: Re: Parser
Post by: tzachs on Sat 25/07/2009 19:17:46
I'm guessing that you parse the text in the repeated execute and that's why the action fires before pressing enter. Instead, you should register to the on key event (you've probably already registered in order to raise the gui), and only when the key is enter you should do your parsing...
Title: Re: Parser
Post by: Ethan D on Sat 25/07/2009 20:31:39
Here is the script I have so far.

function on_key_press(eKeyCode keycode)
{
 if ((keycode == eKeyReturn) && (gGui2.Visible == true))
 {
 String input = TextBox1.Text;
 Parser.ParseText(input);
 gGui2.Visible = false;
 }
 if (Parser.Said("look art"))
 {
 Display("A painting that seems to have been supplied by a certain Jacques Chevrier.");
 TextBox1.Text = "";
 }
}


I'm not sure what's wrong with it.  The Gui doesn't close so I think its a problem near the top but I'm still not sure what.
Title: Re: Parser
Post by: tzachs on Sat 25/07/2009 21:39:28
Try this:


function on_key_press(eKeyCode keycode)
{
  if ((keycode == eKeyReturn) && (gGui2.Visible == true))
  {
     String input = TextBox1.Text;
     Parser.ParseText(input);
     gGui2.Visible = false;
     if (Parser.Said("look art"))
     {
       Display("A painting that seems to have been supplied by a certain Jacques Chevrier.");
       TextBox1.Text = "";
     }
   }
}


I just moved the Parser.Said call into the first condition because otherwise it will check the parser on every key press and you want to do it only after enter...
Title: Re: Parser
Post by: Laukku on Sat 25/07/2009 22:13:56
I would recommend my template: http://www.adventuregamestudio.co.uk/yabb/index.php?topic=9435.msg462815#msg462815
::)
Title: Re: Parser
Post by: Khris on Sun 26/07/2009 11:57:02
Also, you need to clear the text field after the command has been processed.
Title: Re: Parser
Post by: Ethan D on Mon 27/07/2009 20:40:43
Alright I've got it figured out.  Thanks for the help.