Textbox to capture user's input

This forum is meant for people to share their knowledge by writing their own tutorials for Adventure Maker.

Moderators: Vengeance66, Harvester, GM-Support, reneuend, Lyberodoggy, Candle, Mystery, ShadowHunter

Textbox to capture user's input

Postby reneuend » Thu Feb 13, 2014 3:30 am

Here is how to create a textbox to capture a user's input:

From advanced tab on the frame properties:

Code: Select all
LoadControl TextBoxObject(2)

TextBoxObject(2).move 218*15, 251*15, 304*15, 26*15
TextBoxObject(2).visible = True
TextBoxObject(2).Font = "Comic Sans MS"
TextBoxObject(2).Font.size ="12"
TextBoxObject(2).Forecolor = RGB (255,255,255)
TextBoxObject(2).backcolor = RGB(128,64,0)



Add a hotspot (button) for the user to click on to capture the value of the textbox and store it in a (variant) variable:

Button advanced tab:

Code: Select all
MyVariable = TextBoxObject(2).Text


Note: if you want more than one textbox, increment the index in the TextBoxObject(index)
Warning! You won't see the textbox until you run it.
---


Image
Image
User avatar
reneuend
Administrator
 
Posts: 2623
Joined: Sat Nov 22, 2008 8:37 pm
Location: Midwest Cornfield, USA

Re: Textbox to capture user's input

Postby Stitches » Thu Feb 13, 2014 5:21 am

Hi, Reneuend. Cheers for this! Permit me a wee addition...

FOR NAMING A CHARACTER!!!

Create a new frame with whatever nice background asking folk to give a name. Define (via the first code) where you want and customize the colour etc. Once this is done, make the hotspot button. Go to frame properties

Create a new Variant Variable called "Name"
Input the 2nd code
Go to the first tab of the hotspot properties and click "Go to Another Frame" Or code it in whatever you want. Make it go to your first/character page screen.
Here, click right mouse where you want to display the name and input whatever into the textbox
Finally, go to the frame properties and input the VBS code

Text(1).caption = cstr(Name)

DONE! :) If you did this right, the name of your character should appear where you want it on the screen.

:)
http://www.youtube.com/user/MaynardStaly/videos and http://libertycap.webs.com
“With a bit of luck, his life was ruined forever. Always thinking that just behind some narrow door in all of his favorite bars, men in red woolen shirts are getting incredible kicks from things he’ll never know.”
User avatar
Stitches
Active Member
 
Posts: 71
Joined: Tue Nov 12, 2013 3:56 am
Location: UK

Re: Textbox to capture user's input

Postby reneuend » Thu Feb 13, 2014 5:28 am

Thanks Stitch! Good idea!
---


Image
Image
User avatar
reneuend
Administrator
 
Posts: 2623
Joined: Sat Nov 22, 2008 8:37 pm
Location: Midwest Cornfield, USA

Re: Textbox to capture user's input

Postby Paul.S » Fri Nov 27, 2015 8:42 pm

Hi, is there a way to use this technique for entering a password, rather than capturing the entered text as a variable? I have a password stored as a variable but I haven't yet worked out how to use it in game. Thanks!
Paul.S
Member
 
Posts: 23
Joined: Thu Nov 26, 2015 8:53 pm

Re: Textbox to capture user's input

Postby reneuend » Sat Nov 28, 2015 12:40 am

Hi Paul and welcome to the AM forums.

I think you will need to explain in more detail what you are trying to achieve.
Even in real program applications, passwords are taken as text (stored as a variable) and then checked against the user's encrypted password on a database.

Do you want to "mask" the password that is entered? In other words, display asterisks instead of the actual entered text.

or is it that you don't want to create a variable for it, but use a direct check like:

If myPassword = TextBoxObject(2).Text then
'password is correct
else
'password incorrect
end if

Where "myPassword" is the password you have stored.
---


Image
Image
User avatar
reneuend
Administrator
 
Posts: 2623
Joined: Sat Nov 22, 2008 8:37 pm
Location: Midwest Cornfield, USA

Re: Textbox to capture user's input

Postby Paul.S » Sat Nov 28, 2015 2:22 pm

I have used some code to create a 3 digit pass code which is different every time the game is started, and I have managed to create a way of displaying the pass code within the text of a screen that a player has to find in order to get the code. All good so far. What I'm trying to do is create the text box so that when the correct 3 digit code is entered. So I guess I would create the text box and a second hotspot with an "Enter" button, so when the enter button is clicked there would be some code that checks whether the entered code is the same as the variable code that was created earlier.
Paul.S
Member
 
Posts: 23
Joined: Thu Nov 26, 2015 8:53 pm

Re: Textbox to capture user's input

Postby reneuend » Sun Nov 29, 2015 2:53 am

Paul.S wrote:I have used some code to create a 3 digit pass code which is different every time the game is started, and I have managed to create a way of displaying the pass code within the text of a screen that a player has to find in order to get the code. All good so far. What I'm trying to do is create the text box so that when the correct 3 digit code is entered. So I guess I would create the text box and a second hotspot with an "Enter" button, so when the enter button is clicked there would be some code that checks whether the entered code is the same as the variable code that was created earlier.


That seems like a good way to handle it.

Lets say your 3 digit code is in a variable called, "passcode"

When the hotspot is clicked, you can either check it in the Advanced Tab or in a call to a vb script subroutine. I prefer always using subroutines because the code is easier to manage as it puts all your code in one place.

So.....

Hotspot - Advanced Tab:

Code: Select all
If CheckPasscode(TextBoxObject(2).Text) then
  'Passcode matched...do something here
else
  'Incorrect passcode - tell the user
  Action.Message "Incorrect pass code entered"
end if


in the Advanced - Script Area:

Code: Select all
Function CheckPasscode(byval UserVal)
  if UserVal = passcode then
    CheckPasscode = True
  else
    CheckPasscode = False
  end if
End Function
---


Image
Image
User avatar
reneuend
Administrator
 
Posts: 2623
Joined: Sat Nov 22, 2008 8:37 pm
Location: Midwest Cornfield, USA


Return to Post Your Own Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest

cron