Parser

Started by Ethan D, Sat 25/07/2009 01:13:33

Previous topic - Next topic

Ethan D

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? 

Ghost

The on_key_press function() in your global script is called whenever ANY key is pressed, to I'd call the GUI there.

Ethan D

Im having trouble figuring out how to set the Gui so that if you press enter that acts as the parser. Any ideas?

Ethan D

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.

tzachs

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...

Ethan D

#5
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.

tzachs

Try this:

Code: ags

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...

Laukku

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.

Khris

Also, you need to clear the text field after the command has been processed.

Ethan D

Alright I've got it figured out.  Thanks for the help.

SMF spam blocked by CleanTalk