CodeBox displaying numbers pressed (scripting)

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

Moderators: time-killer-games, Vengeance66, Candle, reneuend, GM-Support

CodeBox displaying numbers pressed (scripting)

Postby Lyberodoggy » Thu Mar 06, 2008 4:47 pm

Another fresh idea came to my mind accidentally today and I want to share it with you.

There are other tutorials which show how to create a codebox (a num pad where the player has to press the right sequence of numbers). This tutorial is made to show how to display the numbers pressed in a textbox.

Let's assume you want the player to input a 4 integer standard pin:
Go to the global procedures and type:
Code: Select all
Function buttondisplay(buttonnumber)
If ConvertToNumber(TextBoxObject(1).Text)<=999 Then
TextBoxObject(1).text=TextBoxObject(1).text+cstr(buttonnumber)
End If
End Function

Remember!!! Change the index of the textbox if you use another textbox OR the parser plugin! Change 999 if you want to display more than 4 digits (for five digits enter 9999, for six 99999 etc).
Then go to the frame where your codebox is. Enter this to frame's advanced:
Code: Select all
LoadControl TextBoxObject(1)
TextBoxObject(1).Visible=True
TextBoxObject(1).Move 215*15,384*15,200*15,15*15
Textboxobject(1).Locked=True

Remember!!! Change the coordinates to fit with your project and set the index to an available one (the same as in the function).

Now go to the nine or ten hotspots representing numbers from 0 or 1 to 9 (in this case, you will have a problem if the first digit is 0, so it's not recommended to use 0 first in the sequence). Type in each of them this:
Code: Select all
buttondisplay(1)

where 1 must be changed depending on the number the hotspot is representing.

Create a "Clear" button and type this code in the Advanced:
Code: Select all
TextBoxObject(1).text=""


Finally create an "Enter" button and modify this code to fit to your project:
Code: Select all
If ConvertToNumber(TextBoxObject(1).text)= 1234 Then
MsgBox "You got it"
Else
MsgBox "try again"
TextBoxObject(1).text=""
End If

(change 1234 with the sequence you want, change the actions if the typed sequence is right etc).


Hope it was usefull.
Attaching sample...
Attachments
codeboxdisplaytutorial.rar
(111.17 KiB) Downloaded 573 times
User avatar
Lyberodoggy
Administrator
 
Posts: 2526
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby Candle » Thu Mar 06, 2008 7:49 pm

Nice one Lyberodoggy, thanks.
Please don't PM me questions, ask here in the forums!
``````````````
Between grand theft and a legal fee, there only stands a law degree.
User avatar
Candle
Administrator
 
Posts: 3077
Joined: Sat Feb 07, 2004 2:21 am
Location: Rudy's Bar

Postby Lyberodoggy » Thu Mar 06, 2008 8:42 pm

You are welcome Candle!
User avatar
Lyberodoggy
Administrator
 
Posts: 2526
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby Lyberodoggy » Thu Mar 06, 2008 10:24 pm

Here's an even better one:
Make the textbox appear like an LCD screen.

Use the font I 've included in the new sample's root folder or any other LCD font and these lines of extra code in addition to the rest of the tutorial:

In the frame properties, in Advanced, use this extra piece of code
Code: Select all
TextBoxObject(1).Font="LCD"
TextBoxObject(1).Fontsize=40
TextBoxObject(1).ForeColor=62501
TextBoxObject(1).BackColor=13568
TextBoxObject(1).Fontbold=True

Remember: We want an LCD display, so we need either green digits on black screen or green digits on dark green screen.
use the vbblack and vbgreen colors or the HEX or RGB color codes.
I 've used 13568 (dark green) for the screen and 62501 (green) for the digits.


I 'm sure this is going to make the games more realistic.
If having any problems with the code feel free to ask...
Be sure to install the font I 've supplied you with (it is located in the projects "root" folder) and restart your pc to make it work and if you create a game using a codebox like this, be sure to have the end-user install this font too.
Well, I 'd better go to sleep now, because I have been awake since yesterday (that's why I 'm writing so badly :lol: )
Farewell...
Attachments
codeboxdisplaytutorial.rar
Almost forgot it!!! I need sleep right now... :P
(86.53 KiB) Downloaded 739 times
User avatar
Lyberodoggy
Administrator
 
Posts: 2526
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby Lyberodoggy » Tue Mar 11, 2008 7:34 pm

To kill the bug when using zero in the num pad, which was produced due to Textboxobject(1).Text<999, remove the if from the function we 've created, then go to frame properties and add
Code: Select all
TextBoxObject(1).Maxlenght=4


Phew... Solved!
User avatar
Lyberodoggy
Administrator
 
Posts: 2526
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby dreamfighter » Thu Mar 20, 2008 3:24 pm

it's cool

thank you very much liberdoggy for this tuto
dreamfighter
Member
 
Posts: 22
Joined: Fri Jan 11, 2008 8:22 pm
Location: FRANCE

Postby Lyberodoggy » Thu Mar 20, 2008 4:58 pm

:D You are welcome...
User avatar
Lyberodoggy
Administrator
 
Posts: 2526
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby Tony_LaRocca » Sat Mar 29, 2008 2:55 am

thanks so much - here's a question, though, how would I do it for a text keypad? If I wanted to spell out a password, rather than a number
User avatar
Tony_LaRocca
Member
 
Posts: 34
Joined: Wed Feb 20, 2008 4:14 am

Postby Lyberodoggy » Sat Mar 29, 2008 8:36 am

It's easy:
Code: Select all
displaybutton "the letter you want"

Just remember to change this one accordingly:
In the Enter Button described above, remove the Converttonumber function, because it won't work:
Code: Select all
If TextBoxObject(1).text= 1234 Then
MsgBox "You got it"
Else
MsgBox "try again"
TextBoxObject(1).text=""
End If
User avatar
Lyberodoggy
Administrator
 
Posts: 2526
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby Tony_LaRocca » Sun Mar 30, 2008 3:31 am

thank you kindly!
User avatar
Tony_LaRocca
Member
 
Posts: 34
Joined: Wed Feb 20, 2008 4:14 am

Postby Lyberodoggy » Sun Mar 30, 2008 8:12 am

You are welcome...
User avatar
Lyberodoggy
Administrator
 
Posts: 2526
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby Tony_LaRocca » Sun Mar 30, 2008 10:28 pm

Erm not to be ungrateful, but there seems to be problems with your example.
Displaybutton "text"
gives me an error, but
buttondisplay "text"
Works fine. Also, if I'm using text, I need to enter my correct password in quotes.

one final question:

I see that I have to add something to the global VBS procedures. If I have more than one keypad in the game, do I add a new

"Function buttondisplay(buttonnumber)"

for each one? Is the "buttondisplay" the name of the function? (sorry, but I don't know much about scripting)

Thanks
-Tony
User avatar
Tony_LaRocca
Member
 
Posts: 34
Joined: Wed Feb 20, 2008 4:14 am

Postby Lyberodoggy » Mon Mar 31, 2008 11:46 am

Tony_LaRocca wrote:Erm not to be ungrateful, but there seems to be problems with your example.
Displaybutton "text"
gives me an error, but
buttondisplay "text"
Works fine.

:oops: Sorry, I sometimes forget the names of the procedures... But at least you got the point.

Tony_LaRocca wrote:Also, if I'm using text, I need to enter my correct password in quotes.

Yes, that's something you should know if you want to script, because if you input the string without quotes it will be viewed as a variable

The name of the custom function is what you see in the procedures...
You don't really need to create the procedure several times... just change the ifs...
User avatar
Lyberodoggy
Administrator
 
Posts: 2526
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby mercedes » Wed May 21, 2008 9:22 pm

Lyberdoggy..I just did this piece of code for a question i asked here about a number pad..and this works perfectly..!! Even the coordinates work perfectly with my project..


Along with getting this number...

How do i make the variable fit in with this code..??

Thanks so much for this..!

*EDIT* I figured out the variable..I just added the variable to the word "CLEAR" properties..


Also, don't forget to add in this script...in the frame you either set it to go too...or in the one you go back too...

In the frame properties..

Code: Select all
UnloadControl Textboxobject(1)

Where 1 is replace with the number of your textboxobject..

I hope you don't mind if I add an attachment for those who wish to view what this would look like..If so I can delete it..or you can I guess..lol..

I have recently updated this pictureframe..and have added buttons instead for the words "clear" and "enter"..i just left text right there and placed buttons right on top of the text...looks nice..I love it..I love this tutorial..It won't be the last time I use it..~!

Again Many thanks..!~
Attachments
Picture of number pad.JPG
Picture of number pad.JPG (74.38 KiB) Viewed 14050 times
User avatar
mercedes
VIP
 
Posts: 2460
Joined: Sun Mar 09, 2008 10:43 pm
Location: Canada..~

Postby Chromegloss55 » Fri May 23, 2008 2:21 pm

Another superb tutorial... :)
_________________
how to make hash
Last edited by Chromegloss55 on Tue Feb 24, 2009 3:24 pm, edited 1 time in total.
Chromegloss55
Forum Master
 
Posts: 630
Joined: Sat Nov 03, 2007 2:49 pm
Location: God Knows!

Postby Lyberodoggy » Sat May 24, 2008 9:59 am

mercedes you need to add an additional variable to check wheather the textbox is loaded prior to unloading it, else if you go to the "back" frame and there's no textbox loaded the scripting engine will generate an error trying to unload it.
User avatar
Lyberodoggy
Administrator
 
Posts: 2526
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby mercedes » Sat May 24, 2008 5:00 pm

Would I have noticed that in run time?..And why is that..ive unloaded all control boxes..like that in other frames..? Whats the difference with this one..?

EEK..i have already compiled it..not advertised it but compiled it..didnt notice anything..I have someone testing it as we speak...time will tell...~
User avatar
mercedes
VIP
 
Posts: 2460
Joined: Sun Mar 09, 2008 10:43 pm
Location: Canada..~

Postby Lyberodoggy » Sun May 25, 2008 3:38 pm

If you didn't have any probs while debugging, then there's nothing to worry about.
User avatar
Lyberodoggy
Administrator
 
Posts: 2526
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby mercedes » Sun May 25, 2008 11:47 pm

I've never used the debugging feature..curious what that's about....and yes..i have had it tested a few times..it's fine..So far so good..!~
User avatar
mercedes
VIP
 
Posts: 2460
Joined: Sun Mar 09, 2008 10:43 pm
Location: Canada..~


Return to Post Your Own Tutorials

Who is online

Users browsing this forum: No registered users and 0 guests

cron