Multiple Text Boxes, Advancing by Hitting Enter? [SOLVED]

Started by Play_Pretend, Wed 19/12/2007 00:48:47

Previous topic - Next topic

Play_Pretend

Hi all...I'm in a pickle over this, it's for a project due tomorrow. :)  I need to have five textboxes on the screen at once, and the cursor to start in the first one.  When the player types in their first word and hits enter, it'll advance to the next box and let them type in their next answer, and so on down.  Each answer has to stay visible in the box in the meantime.

I already hid the real text boxes off screen, and used the Repeatedly Execute so they would update corresponding labels on the screen.  I tried using the Visible command to make each text box turn off and turn on the next one when an answer was keyed in, but it doesn't do anything.  The first box just sits there.  Am I using the wrong command?  Thanks!

monkey0506

#1
You could do leave the text boxes on the GUI at their normal position and just do something like this:

Code: ags
function game_start() { // alternatively, do this when turning on the GUI or entering appropriate room
  txtTextbox1.Enabled = true; // first text box active (visible and intercepting typing)
  txtTextbox2.Enabled = false; // all others inactive
  txtTextbox3.Enabled = false; // (visible, but won't intercept typing)
  txtTextbox4.Enabled = false;
  txtTextbox5.Enabled = false;
  }

function txtTextbox1_Activate(GUIControl *control) {
  txtTextbox1.Enabled = false; // deactivate first text box
  txtTextbox2.Enabled = true; // activate second
  }

function txtTextbox2_Activate(GUIControl *control) {
  txtTextbox2.Enabled = false;
  txtTextbox3.Enabled = true;
  }

function txtTextbox3_Activate(GUIControl *control) {
  txtTextbox3.Enabled = false;
  txtTextbox4.Enabled = true;
  }

function txtTextbox4_Activate(GUIControl *control) {
  txtTextbox4.Enabled = false;
  txtTextbox5.Enabled = true;
  }

function txtTextbox5_Activate(GUIControl *control) {
  // verify answers and whatnot
  }


AFAIK the text box text should still appear even if the control is disabled. If I'm mistaken about this, let me know.

Another possibility (to cut down on the number of functions) would be to use one 'Activate' function for all the text boxes which could be done by pointing them all to one 'txtTextbox_Activate' function such as this:

Code: ags
function txtTextbox_Activate(GUIControl *control) {
  if (control == txtTextbox5) {
    // verify answers and whatnot
    return;
    }
  control.Enabled = false;
  if (control == txtTextbox1) txtTextbox2.Enabled = true;
  else if (control == txtTextbox2) txtTextbox3.Enabled = true;
  else if (control == txtTextbox3) txtTextbox4.Enabled = true;
  else if (control == txtTextbox4) txtTextbox5.Enabled = true;
  }

Play_Pretend

I just plugged in your first solution, and my program still sat still at that first text box when I hit ENTER.  Then I carefully re-read my programming, spotted the:

if (GetGlobalInt(2) == 3) {

that I'd left sitting right above my text activation code, realized that since I was jumping ahead to a room where that variable had *not* been set to 3, and thereby had been screwing myself stupidly this whole time. :)  Sure enough, I set the variable right, and bam, your solution worked perfectly.

I feel like such an ***. :)

On the other hand, you not only gave me a simple and elegant solution, but you made me realize that I, like a schmuck, did not have to use five separate GUI's with one textbox apiece, but could put all five boxes in one GUI.  Since I was figuring on Visible-ing each of the GUIs, it just never occurred to me.

Thank you *so much* for helping me out, I might have to post this thing on here, maybe in the Joke Games section.  It's a really simple, cheesy Family Feud parody for a meeting at work, to teach people there about work processes. :)  But yeah, seriously, thank you, thank you, thank you!!! :)

monkey0506

#3
I'm honestly glad to have helped. One of the things I always loved about AGS was learning how to do new things. I started off with very limited programming experience whatsoever, and AGS has helped me to greatly build upon that.

Five separate GUIs would be a bit much for this task, though I can understand how you might have reached the idea that you would need to do this. Regarding the visibility however, GUIControls (i.e., TextBoxes) have Visible properties as well (txtTextbox1.Visible = false;), though as we've seen, you didn't want to turn them off, just disable them. That's why we have separate TextBox.Enabled and TextBox.Visible properties. Enabled will control whether the TextBox is active: whether it is currently intercepting typing as well as whether pressing the Enter key will call its 'Activate' function. Visible however actually controls whether the TextBox is shown on the GUI or not.

Again, I'm glad to have helped you. Like I said, AGS is a great learning experience.

SMF spam blocked by CleanTalk