Page 1 of 1

How to create a textbox to let the player type in a password

PostPosted: Mon Dec 03, 2007 9:50 am
by Mystery
I've been asked how such a puzzle works, therefore I've decided to make a thread about it for everyone to use. Of course you can adapt this example to your own needs.

Create for example a door, and make a hotspot over the door knob. Don't forget to add also a hotspot that the player can click to leave the screen.

Open the Frame Properties and go to the Advanced Tab. Enter the script:
Code: Select all
LoadControl TextBoxObject(1)
TextBoxObject(1).Move 240*15,300*15,300*15,30*15
TextBoxObject(1).Visible = True


To change the position and size of the textbox, replace the values in the above code according to LEFT*15,TOP*15,WIDTH*15,HEIGHT*15. To figure out the correct values may take some playing around.

Then open the Hotspot Properties of the hotspot over the doorknob, go to the Advanced tab and enter (in this example "Guard" is the correct password):

Code: Select all
If TextBoxObject(1).Text <> "Guard" Then
   Message "The password seems to be wrong."
Else
   Action.GoToFrame "FrameName"
End If


Please note that you need to unload the textbox object on all screens where the player can go after that (for example the screen where the player goes after entering the correct password; and the screen where the player goes when he/she leaves the screen without entering the correct password), otherwise the textbox will be displayed on all the following screens.
So for each screen where the player might go next, open the Advanced Tab of the Frame Properties (or the Advanced Tab of the Hotspot Properties of the hotspot that the player clicks to leave the screen), and enter:

Code: Select all
UnloadControl TextBoxObject(1)


To add more similar puzzles, just change the number of your TextBoxObjet. The next one would be TextBoxObject(2).

Let me know if anything is not clear :)

PostPosted: Mon Dec 03, 2007 9:54 am
by Candle

PostPosted: Mon Dec 03, 2007 9:56 am
by Mystery
Yes, it's very similar, but in this example the player can enter something in a textbox instead of a pop-up message box.
It's also very good for pc passwords for example. :)

PostPosted: Mon Dec 03, 2007 10:00 am
by Candle
That would be called an edit box then. so yes yours is better .
I have been wondering how to do that too.
Thanks much for it :)

PostPosted: Mon Dec 03, 2007 10:06 am
by Mystery
You're welcome :)
Have fun using it :D

thanks

PostPosted: Tue Dec 04, 2007 2:55 am
by Crazygamemaker
Just what I was looking for.
Thank you Mystery! :D

PostPosted: Sat Dec 08, 2007 3:10 pm
by Chromegloss55
Just an additional little thing (and this has been included in my 100 Visual Basic Techniques), you know when you type into a password box you only see: ***********

Well the code to make that happen uses the PasswordChar property.

This is the code:

TextBoxObject(i).PasswordChar = "*"

At least I think it is. If I'm wrong I'll correct it.
_________________
Finnish Forum

One Question...

PostPosted: Sat Feb 23, 2008 12:40 am
by Tony_LaRocca
This is great- but is there any way to have the password input using the "enter" key rather than having to click on the hotspot? Thanks

PostPosted: Sat Feb 23, 2008 1:03 am
by Mystery
Unfortunately not to my knowledge.
There is a need for the hotspot to check the entered data.

is there any way...

PostPosted: Sat Feb 23, 2008 3:00 am
by Tony_LaRocca
How would I go about putting in the possibilities of different answers? I've tried adding other if - then routines, but I must be doing something wrong, because I get an error:

If TextBoxObject(1).Text = "password" Then Action.GoToFrame "room"

If TextBoxObject(1).Text = "pass" Then Message "Could you use more letters, please?"

Else Message "Better luck next time"

End If

The scripting box gives me an "expected end" error. Sometimes, it gives me an "Expected If" error.

Thanks!

Never mind, I've sussed it

PostPosted: Sat Feb 23, 2008 7:46 am
by Tony_LaRocca
Got it - using the "elseif" command:

If TextBoxObject(1).Text = "Password" Then
Action.GoToFrame "forbidden-room"
Elseif TextBoxObject(1).Text = "open" Then
Message "Think it's that easy?"
Else
Message "Try again!"
End If

PostPosted: Sun Feb 24, 2008 3:11 am
by Mystery
I'm too late, glad you figured it out meanwhile :)

PostPosted: Tue Feb 26, 2008 7:56 pm
by Chromegloss55
The scripting engine can be so fussy sometimes!

An easiar way to do it would have been to use the Select Case command, it works better than loads of If...Then statements. But whatever gets the job done...
_________________
how does a stock market crash

PostPosted: Thu Apr 17, 2008 5:07 am
by Cat
Thanks so much for this!

PostPosted: Mon May 05, 2008 9:21 pm
by mercedes
This is perfect..


But there is one thing though that I would like to do..for this particular text box..i have yet to try it..im assuming and hoping it will go smoothly..lol..

what i would like to do is add underneath it..
not in the box itself if possible..
i want to add the word "hint" and when they click the word "hint' appears the hint.."Theyre red and they bark..whatever..anything..and it can either go away after a few second or when they leave the screen..and have to click it again..when they come back to it..<<this part doesnt matter..so much.

Is this possible Mystery..? I'm not really sure what its called what im asking for ..i think ive seen it in riddles..but was hoping you could add it in here..? :oops:

any input would be great..I figure i might as well wait to see if this can be done before i add the box..kinda tells me where to add hints else where..lol..if this doesn't work..~

Also why is hotspot over doorknob and not center of door where the code box is..?

PostPosted: Tue May 06, 2008 6:01 am
by Mystery
Of course you can add a "hint" icon in a hotspot.
Then you need to go to the Hotspot Properties, and choose what should happen when it's clicked (for example a hint message is displayed).


For the doorknob question:
Well it's just an example in the first post, you can put the hotspot whereever you like, and change the script according to your own needs ;)

PostPosted: Tue May 06, 2008 6:06 am
by mercedes
OMG..am i ever a bonehead..that never even occured to me..lol..


i have this code in there now and i keep getting an error..what am i doing wrong..was following a tutorial...i must have typed something wrong..?


Code: Select all
LoadControl TextBoxObject(1)
TextBoxObject(1).Visible = True
TextBoxObject(1).Left = 212*15
TextBoxObject(1).Top = 212*15
TextBoxOjbect(1).Width = 146*15-------------ojbect
TextBoxObject(1).Height = 14*15



edit..never mind i see it..i copied and pasted it..without even thinking it could be spelled wrong..lol..


Im a bit confused now though..ive entered this in as it is.in the frame properties ..and i see that the code you entered starts off with the the code in the frame properties but you enter the answer to end of code..like where u put answer is in the hotspot of doorknob..what do i do..does it matter..?

PostPosted: Tue May 06, 2008 6:42 am
by Mystery
I'm not quite sure if I understand what you mean mercedes.

You need a hotspot that checks the player's answer (compares password with what the player has entered).
I've chosen for that a hotspot over the doorknob, but you can add any kind of hotspot, for example a "ENTER" icon, "CHECK" icon etc.

PostPosted: Tue May 06, 2008 6:47 am
by mercedes
ohhhhh..ok..i was basically wondering why it was started in frame properties and ends in the the hotspot over doorknob...but i get it now..basically all that hotspot is there for is to check it.. so this way door either opens or it doesn't saying whatever..i get it. now..

THANK YOU..~! :lol:

first time ive ever done it..so it seemed strange to me..but its like an enter button ..didn't recognize it as checking the answer..sorry about that..~ If you have never done it before..its a bit confusing but i see now what all together purpose of it.


thank you for clearing that up..

I ended up using this code ...was alot easier for me to use and understand..just wanted to know why and what it was i was doing..

could you explain why the word "move" in the code plz..

Also i thought that left top and width and height all applied to the box..the text box but it doesnt..

top and left apply to frame position
height and width apply to text box....

took me a bit of reading to see that ....:) Thanks to Chromeglass for putting that in his tutorial..as well as why the number 15 was in the code ..it's measured in pixels..so * it by 15..aha..lol..

Between all of the coding gurus on this site..I'll get er done..~..

many thanks..~~!@!! :lol:

PostPosted: Tue May 06, 2008 6:57 am
by Mystery
Yes, exactly - the hotspot is used to CHECK the answer :D

No need to apologize, it can be pretty difficult to understand for new users. And only if you understand the examples, you will be able to change them according to your own needs.

Glad you have figured out, and understood how this password example works :)