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!
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.
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.
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.
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.
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á!
:'( 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.
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?
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
}
}
}
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.
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.
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
Ã, Ã, }
Ã, }
}