Custom Input Box

Started by , Sun 04/04/2004 02:32:25

Previous topic - Next topic

AGS Newbie

Hi, everyone ! I'm a bit confused about how to make a custom Input Box for entering and checking data. I know that from the manual there is a built in function, " InputBox ", but in this case, it doesn't really provide a solution. In my case, I'm trying to accomplish the following two things:

1. Create a Custom Input Box in which I can have a user type in a password, which has already been defined in a string, using the built in, "InputBox". This Custom Input Box will need to be able to check if the password is valid, and if so, allow continution, and if not, reject and reset itself for another attempt. I've already created a functional GUI, but do not know how to script it to parse accordingly, checking the input, in relation to the actual password.

2. Is it possible that upon entering characters into this Custom GUI, ( Input Box ) that they can be represented by asterixes, ( * ) similar to commercial products ?

Example:

Password = AGS
Password Input to be Checked = ***

Thanks for any suggestions or code that would help.

ElectricMonk

The simplest solution might be to create a font that consists only of asterisks instead of letters, and set the input box to use that font...

AGS Newbie

Thanks, that's something to consider, in any case. Although, the whole parsing and error checking dilemna still remains...

ElectricMonk

#3
Read the help file on GetTextBoxText,
then resolve the issue with something like

if ((GetTextBoxText(8,2, password) == "AGS"))
{ whatever you want to happen }
else
GUIOff(8);
Display("Wrong password!");
SetTextBoxText(8, 2, ""); // clear the entry box again

For this purpose, I'm assuming that your GUI is no. 8 and the text box is  object no. 2 on that GUI.

AGS Newbie

Great, thanks, that's exactly the kind of idea I've been seeking. Unfortunately though, doing it that way seems to result in a mismatch error, " Mismatch: String with Non-String". In addition, I'd like to read the password from a string, so the password isn't always the same, not always being "AGS". If a player enters the password through an "InputBox" command, for the Custom GUI box to be able to read the password from the actual string, opposed to having the password predefined, as stated above.

ElectricMonk

Sorry, my fault... turns out things are a little more complicated...
but now that I've tested it myself (hey, it's good practice for me as a newbie...)

In the global script, between the brackets of function game_start(), include

SetGlobalString(15, "");

or any other global string for that matter, just make sure you haven't used it yet. Global string 15 will be the placeholder for the password in future.

At any time you like, you can now set the password, for example

SetGlobalString(15, "Swordfish");

Then, before you check the input, read the value of global string no. 15 into the local string "password" (first, of course, also defining "password" as a string), and read the value of your text input into the string "textinput".


string password;
string textinput;
GetGlobalString (15, password);
GetTextBoxText(8,2, textinput);


Now all you have to do is compare the two strings textinput and password and see if they match. A simple == check won't do it, you have to use
if (StrCaseComp(textinput, password) ==0)
Apologies for not knowing this before, but then it's your own damn fault for not reading the manual. ;)

The whole checking thing, once again (without the one line needed in the global script), to be entered in the script for your GUI:


if (interface == GUI8)
{
    if (button == 2)  // enter is pressed, i.e. object 2 (text box) is activated
       {
        string textinput;
        string password;
        GetGlobalString (15, password);
        GetTextBoxText(8,2, textinput);
        if (StrCaseComp(textinput, password) ==0)
           {
            GUIOff(8);
            Display("Password correct");
            SetTextBoxText(8, 2, "");
           }
    else
          {
            GUIOff(8);
            Display("Wrong password!");
            SetTextBoxText(8, 2, "");
           }
       }
}  // end if interface GUI8


SMF spam blocked by CleanTalk