More info on text parser?

Started by Sonja, Fri 23/12/2005 09:10:40

Previous topic - Next topic

Sonja

I've read the info about the text parser in the manual. Is there a FAQ or expanded parser information or tips page somewhere? I plan to use this feature extensively, so I'd like to browse through all sorts of issues or examples or questions to learn from them.

For example it says "Well, you'll need a text box GUI control somewhere in order for the user to type in their input." but it doesn't seem to give some examples on some common ways to do this. Or maybe I need to find that information in another section somewhere?

Sonja

Sonja

I understand the part about the synonyms. The parts that are not really explained step-by-step are how to set up a window where the player can type the commands, and where to put the script that scans through what the player is trying to do (does it go in global?) etc.

Elliott Hird

Mmm I made a cleaner template than Magintz's one but i lost it... mmmmm gonna change system clock and recode it... pm me

SilverWizard_OTF

Well, you can use the script command InputBox(....). Ehm, at least that was the script command to AGS version 2.6 Something like that should exist to your version
 
"All we have to decide is what to do, with the time that is given to us"

Sonja

Quote from: SilverWizard_OTF on Sun 25/12/2005 21:28:53
Well, you can use the script command InputBox(....)

The manual says:
"NOTE: This command displays a very basic input box, mainly useful for debugging purposes. The recommended way to obtain user input is to create your own GUI with a text box on it, which allows you full customization of the look of the window."

I guess I need a tutorial on how to do that. :-( I wish there was more support for the parser feature.

Elliott Hird


monkey0506

#6
Or you could just offer her help instead of trying to keep all your solutions to everyone's problems secret.

Sonja

I sent an email. Should I PM as well? Oh, and I'm female. :P

monkey0506

#8
Sorry about that. :-[

Okay, basically what you want to do is this:

[AGS 2.7 AND LATER]

Open you game.  Click on the GUI pane in the side panel, then click on the GUI menu, and then New GUI.  For simplicity, I won't bother resizing/recoloring the GUI.  Then, beneath the GUI name text box, there are six buttons.

The third one from the left creates a new Text Box, so click on that one.  Then you draw the Text Box onto the GUI.  Next you need to give it a name.  Just for an example, I'll name it txtParser.

Then double click where it says "Activate | (no script)" and give your function a name (the default name should be fine).  Then inside of the function body (between the '{' and '}') type the correct lines for your version of AGS:

Code: ags
// AGS VERSION 2.7
string command;
txtParser.GetText(command);
Parser.ParseText(command);

// AGS VERSION 2.71 AND LATER
if (txtParser.Text != null)
  Parser.ParseText(txtParser.Text);


------------------------------------------------------------------------------

[AGS 2.62 AND EARLIER]

Open you game.  Click on the GUI pane in the side panel, then click the "Create New GUI" button.  For simplicity, I won't bother resizing/recoloring the GUI.  Rename the GUI to something like "TXTPARSER".  Then, beneath the GUI name text box, there are six buttons.

The third one from the left creates a new Text Box, so click on that one.  Then you draw the Text Box onto the GUI.

Now go to Script -> interface_click to open the script to the interface_click function.  Then, at the end of the function (before #sectionend interface_click AND before the last closing bracket '}'), type the following code:

Code: ags
  else if (interface == TXTPARSER) {
    if (button == 0) {
      string command;
      GetTextBoxText(TXTPARSER, 0, command);
      ParseText(command);
      }
    }


Where TXTPARSER is the name of your GUI, and the text box is control (object) 0 on the GUI.

------------------------------------------------------------------------------

That sets up a new text box to work with the text parser.  Then you can just use the built-in parser functions (AGS 2.62-: Said, SaidUnknownWord; AGS 2.7+: Parser.Said, Parser.SaidUnknownWord).  That should hopefully get you started.  If you need more help read over these functions in the manual, and if you still don't understand, feel free to ask. :=

[EDIT:]

I forgot that new style Strings weren't implemented until 2.71, so I fixed that.  Also, I'm not sure if built-in Strings like TextBox.Text can ever be null, but I added a check just in case.

SMF spam blocked by CleanTalk