Switching between two TextBoxes - AKA Login Screen

Started by bulka_tarta, Sat 18/02/2017 21:41:54

Previous topic - Next topic

bulka_tarta

Hi,

This is probably super easy to do, but I am no programming guru :(

I'm trying to create a login screen for a computer interface.
Basically I have a GUI with two TextBoxes, and when player types in correct username and password it will pop up a new GUI (computer screen).
The problem is that whenever you get to the login screen, both textboxes work at the same time.

This topic was the closest thing I found to get this to work (link).

That's the code I use:
Code: ags

function on_event (EventType event, int data) {

   // when a mouse button is pressed down over a GUI
   if (event == eEventGUIMouseDown)
   {
      if (gui[data] == gLoginScreen) // <-- remove it to effect an arbitrary GUI
      {
         GUI *theGui = gui[data];
         TextBox *theTextbox = null;
         GUIControl *control = GUIControl.GetAtScreenXY( mouse.x, mouse.y );
         if (control) 
          theTextbox = control.AsTextBox;
         if (theTextbox)
         {
            // disable GUI textboxes
            int i = 0;
            while (i < theGui.ControlCount)
            {
               if (theGui.Controls.AsTextBox)
               {
                  theGui.Controls.AsTextBox.Enabled = false;
               }
               i++;
            }
            // but enable the selected one:
            theTextbox.Enabled = true;
         }
      }
   }
}


However, I get error message saying: "Error (line19):'[' expected".

Using a different code, I have managed to get the text parser to work, in a sense that when you type in "username" it takes you to the next screen. The problem is that when you type "username" it appears in both textboxes, and I would like to make it work so that you need to have correct phrases in both textboxes (different ones) in order to get you to the next screen.

Cassiebsg

I've stumbled into this problem also, my solution was to "deactivate" the textboxes you are not using when opening a new one. You can transfer the username into a label and show it so you don't lose the "username" line.

There are those who believe that life here began out there...

bulka_tarta

Thanks, so it would be something like this: When Texbox1 is active, so is the Label2. When Textbox2 is active, disable Textbox1 and show Label1.

I think the problem would be that I need two textboxes at the same time, as the player needs to see both - username and password needs to be visible and checked against to prompt to the next screen.

I was considering using Hotspots for this too, so when you click on Hotspot1, enable Textbox1. If clicked on Hotspot2, enable Textbox2. The problem with this is that it will be a lot of work, if I ever want to move the GUI around - it would mean re-doing all of the hotspots.

Cassiebsg

No, the problem is that all open textboxes will be reciving the input from the keyboard, not just the active textbox.

If you wish to "simulate" that the 1st text box is still open, then make a image of the empty textbox, then display the image as button with the text entered in textbox 1. Do the same for textbox 2, in case the player clicks to return to edit the username.

Unless there's another simpler way to do this that I don't know about. (wtf)

Also when I said that " You can transfer the username into a label and show it so you don't lose the "username" line." I meant that exactly what you mean with then "as the player needs to see both - username and password needs to be visible".



There are those who believe that life here began out there...

Snarky

There's a module called MultiTextBox that provides exactly the functionality you need. Get it here: http://americangirlscouts.org/agsresources/modules.html

bulka_tarta

That's awesome!
Initially, I had some problems with the module, but I have managed to get it to work.

I found out that the part which changes the color of selected TextBox (THIS:)
Code: AGS

minlab.TextColor=color; 

Crashes the game. I commented it out for now, but it would be nice to have the selected TextBox to change color. I couldn't find anything on "minlab", I'm not sure if it's something that's now obsolete?


Ok, so that would be it for having multiple TextBoxes. However, I can't figure out a way to get the Parser to work for each TextBox. I want to check (function Button_OnClick) that if both TextBoxes have something specific in them.
Code: AGS

  gLoginScreen.Visible = false;
  Parser.ParseText(txtUsername.Text);
  Parser.ParseText(txtPassword.Text);
  String badword = Parser.SaidUnknownWord();
  if (badword != null){
    Display("Wrong cridentials");
    gLoginScreen.Visible = true;
  }
  Parser.ParseText(txtPassword.Text);
    if (badword != null){
    Display("Wrong cridentials");
    gLoginScreen.Visible = true;
  }  
    else if ((Parser.Said("codebank"))&&(Parser.Said("password"))){  // How to determine which Parser is which? 
    gBankOS.Visible = true; 
    } 


However, the above does not determine which Parser is which.
As for now, I simply checked if Textboxes have exactly the things I need the player to type in them, with a code like this:
Code: AGS

  gLoginScreen.Visible = false;
  if ((txtUsername.Text == "codebank") && (txtPassword.Text == "password")){
    gBankOS.Visible = true;
  }
  else {
    Display("Wrong Cridentials");
    gLoginScreen.Visible = true;
  } 


That piece of code does exactly what I want, which is to make another GUI visible if Username and Password are correct and if they are not (or are empty) to say that they are invalid. However, I'm not sure how would something like this work if I wanted to have more TextBoxes to be filled in at once. For example, if Player needs to fill in 5 TextBoxes (with correct info) to fill in a form on a computer. Having &&, &&, && doesn't seem very efficient and I was wondering if there would be a better way to approach this (perhaps with the Parser).



SMF spam blocked by CleanTalk