my GUI text box won't give the player a chance

Started by Em, Sun 22/02/2009 09:56:44

Previous topic - Next topic

Em

Hello,
I'm trying to make a the player enter a password into a text box when they try to use a door to be able to progress in the game.
I've made a GUI with a text box as described in the PDF guide and in an earlier forum post back in January. This duly appears when the player interacts with the door, but doesn't give the player time to enter anything before the next thing happens - it goes straight to the "wrong password" type response.
I have tried setting my GUI properties to both "pause game when shown" and "normal, initially off", but this makes no difference. Do I need to block something somewhere?

Here is what I've done, forgive me if it doesn't look too nice, I'm new to this.

function hBathdoor_Interact()
{
cDoorvoice.Say("What's the password?");
gPassword.Visible=true;
if (TextBox1.Text=="cheese"){
cDoorvoice.Say("Come on in.");}
else {cDoorvoice.Say("Nope.");
}
TextBox1.Text="";
}

What haven't I done? Thanks a lot for your help.
Em

Akatosh

What your code does is show the player a text box, then immediatly check its contents before the player has any chance to enter something. I recommend using the Game.InputBox command, but if you absolutely have to use your custom password GUI, you should add a "Submit" button to your GUI (if you haven't already) and put this part of the code

Code: ags

if (TextBox1.Text=="cheese"){
cDoorvoice.Say("Come on in.");}
else {cDoorvoice.Say("Nope.");
}
TextBox1.Text="";


in its interaction section. I hope I'm making sense, I'm not exactly awake yet...  ;)

Em

Hurrah, I've added a button, it seems to be working now.
Sorry to be asking questions so early on a sunday morning...
Thanks for your help!

AdamM

#3
Remember that if you don't want to use a button, you can also use the player pressing Return as a trigger. The function that is called when this happens is OnActivate, and you'll find it in the Events List for your Text Box.

Em

thanks a lot, I thought I'd read that somewhere!
There's so much to take in though when you're new to AGS...

Trent R

Or, you do both. Just call the button's event from the textbox, or vica versa.

~Trent
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

Khris

Or enter the function's name in both fields.

Em

wow, so many possibilities! I'll try them out.
thanks a lot for all your answers.
Em

SMF spam blocked by CleanTalk