How to make a Text Box?

Started by Meny, Sun 09/12/2007 00:51:41

Previous topic - Next topic

Meny

Hi, I am kind of new at this, I am working with AGS for a year or less but I don't know everything.
Ok, the problem is that I can't make a text box. I had never done it before and when I had tried I had failed.
I tried to search for a solution in here but I failed again, I was never good in this. (:
So, in the game that I'm working on now, I want the player to use his laptop and search in the "web" for something (to "google"), and when I check the guide and copy the orders it tell me that they are old.
So what do you think should I do? If you can't bring me the directly the answer, maybe you can provide me a link to some place that answers it.

Sorry for my bad english.. :) this forum ROCKS!

Thank you very much!                 

Scorpiorus

Hello and welcome to the forums! :)

As for your question, create a new GUI in the GUI Editor. Next click the "Add GUI Text Box" button and "draw" a textbox within the GUI area. Give this newly created textbox a script name. Double-click the textbox to add a function into the main global script to handle user input; add some code to test it in there:


function textbox-script-name-here_Activate(GUIControl *control) {

    // do the following when the player pressed the Enter key while
    // the textbox's GUI is being shown.


    Display( "You have just typed-in: %s", control.AsTextBox.Text );
}


See if it helps you to start getting it worked out.

Meny

Thank You!  ;D
It work's, but I have still more problems. First of all what actually â€"
control.AsTextBox.Text mean?
Second thing, I want to make some few possibilities. Like, when the player put some specific text he will get one thing and when he will put something different he will get other thing.

One more question, I try to put not an English text and it can't show it, despite the font can support it. Why it happen? It just can't be?
   

Khris

1. The function is called with the parameter "control", it's a pointer to the textbox itself.
You can use it e.g. to get the text that was typed in, as was shown by Scorpiorus.
However, the pointer is still formatted as GUIControl. To convert it to an actual textbox, you have to use the .AsTextBox method. Adding .Text will then return the text that was typed in by the player.

To react to the text, you can do this:

Code: ags
function textbox-script-name-here_Activate(GUIControl *control) {

  String s=control.AsTextBox.Text;

  if (s=="Hello") Display("Hello yourself!");
  if (s=="I want") player.AddInventory(inventory[1]);
}


About the font: try changing the textbox's font to the one you imported. In the GUI editor, select the textbox, then put the font's number into the Font field in the properties pane.

Meny

Thank you!
Now I know how to work with the text box. At least the basics.  ;)

SMF spam blocked by CleanTalk