Password GUI

Started by Gepard, Sun 25/02/2007 11:07:55

Previous topic - Next topic

Gepard

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!
Drink up me 'arties! Yo ho!

Akatosh

The most basic method:

Code: ags

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.

Gepard

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.
Drink up me 'arties! Yo ho!

Akatosh

No problem. Just create a new GUI (must contain a textbox) and put this code in e.g. a button_click method:

Code: ags

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.

Gepard

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.
Drink up me 'arties! Yo ho!

Akatosh

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á!

Gepard

 :'( 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.
Drink up me 'arties! Yo ho!

Akatosh

Oh, yeah, I forgot... of course, you need

Code: ags

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?

Gepard

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
}
}
}
Drink up me 'arties! Yo ho!

Akatosh

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.

Gepard

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.
Drink up me 'arties! Yo ho!

Gilbert

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:
Code: ags
#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
 Ã,  Ã, }
 Ã, }
}

SMF spam blocked by CleanTalk