Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Gepard on Sun 25/02/2007 11:07:55

Title: Password GUI
Post by: Gepard on Sun 25/02/2007 11:07:55
Ok, now I know there are several topics listed for this problem, but they are for the older version of AGS and if they are not, I dont know where to put the scripting, what to type and so on... So I need a guide for lamer like me:

When my character use inventory on object, I want a GUI to come up and ask the player for a password. If he types in the right one, he will proceed, if not, the GUI will close and some message will display.

Thanks a lot!
Title: Re: Password GUI
Post by: Akatosh on Sun 25/02/2007 11:30:56
The most basic method:


String input=Game.InputBox("Please enter your password.");

if (input=="asdf") {
//code here
}

else Display("Wrong password.");


Just replace "asdf" with your password and //code here with, well, your code if the player entered the right password.
Title: Re: Password GUI
Post by: Gepard on Sun 25/02/2007 11:52:42
Yep, that is working, thanks. But I really need a custom GUI that will have the same function as input box, but will look better.
Title: Re: Password GUI
Post by: Akatosh on Sun 25/02/2007 11:57:53
No problem. Just create a new GUI (must contain a textbox) and put this code in e.g. a button_click method:


if (playerenter.Text!="") {
String input=String.Format("%s", playerenter.Text);

if (input=="asdf") {
//code here
}

else Display("Wrong password.");


Where playerenter is the name of your textbox.
Title: Re: Password GUI
Post by: Gepard on Sun 25/02/2007 12:48:21
Which button_click method? I dont exactly know where to put it. When the GUI come up now, it is called password, it is not possible to interact with it and it is grey.
Title: Re: Password GUI
Post by: Akatosh on Sun 25/02/2007 12:50:21
Put a texbox named "playerenter" (for example) and a button on it. Give the button a script name, double-click on it, click on OK, enter the code et voilá!
Title: Re: Password GUI
Post by: Gepard on Sun 25/02/2007 12:54:54
 :'( I feel like a complete idiot. I did exactly as you said, but the GUI just come up and my mouse cursor change into "Wait" mode and I can do nothing. GUI is inactive.
Title: Re: Password GUI
Post by: Akatosh on Sun 25/02/2007 13:05:43
Oh, yeah, I forgot... of course, you need


gPassword.Visible=false;


after else Display("Wrong password."); so that the GUI vanishes again after the player entered something.

/EDIT: Wait, after the GUI comes up? "Clickable" is set to "yes", right? No other code than the code I told you, right?
Title: Re: Password GUI
Post by: Gepard on Sun 25/02/2007 13:11:29
Well now it looks like this:

#sectionstart ok_Click  // DO NOT EDIT OR REMOVE THIS LINE
function ok_Click(GUIControl *control, MouseButton button) {

if (password.Text!="") {
String input=String.Format("%s", password.Text);

if (input=="1111") {
    // my code
}
}
}
Title: Re: Password GUI
Post by: Akatosh on Sun 25/02/2007 13:14:03
And it freezes right after you open the GUI? Or after you enter a password? Also, put gPassword.Visible=false; between the last two } brackets.
Title: Re: Password GUI
Post by: Gepard on Sun 25/02/2007 13:16:35
Well, I will have to see what is wrong with it. Thanks for your help. I couldnt get this far without that code. Its really difficult. Thanks a lot. Will let you know in an hour or so.
Title: Re: Password GUI
Post by: Gilbert on Sun 25/02/2007 13:18:52
I don't have enough info on your problem yet. But just a reminder, there's no need to do the redundant step to reformat a new String for comparison, you can just do it like:
#sectionstart ok_Click Ã, // DO NOT EDIT OR REMOVE THIS LINE
function ok_Click(GUIControl *control, MouseButton button) {
Ã, if (password.Text!="") {
Ã,  Ã, if (password.Text=="1111") {
Ã,  Ã,  Ã, // my code
Ã,  Ã, }
Ã, }
}