Page 1 of 1

CodeBox displaying numbers pressed (scripting)

PostPosted: Thu Mar 06, 2008 4:47 pm
by Lyberodoggy
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...

PostPosted: Thu Mar 06, 2008 7:49 pm
by Candle
Nice one Lyberodoggy, thanks.

PostPosted: Thu Mar 06, 2008 8:42 pm
by Lyberodoggy
You are welcome Candle!

PostPosted: Thu Mar 06, 2008 10:24 pm
by Lyberodoggy
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...

PostPosted: Tue Mar 11, 2008 7:34 pm
by Lyberodoggy
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!

PostPosted: Thu Mar 20, 2008 3:24 pm
by dreamfighter
it's cool

thank you very much liberdoggy for this tuto

PostPosted: Thu Mar 20, 2008 4:58 pm
by Lyberodoggy
:D You are welcome...

PostPosted: Sat Mar 29, 2008 2:55 am
by Tony_LaRocca
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

PostPosted: Sat Mar 29, 2008 8:36 am
by Lyberodoggy
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

PostPosted: Sun Mar 30, 2008 3:31 am
by Tony_LaRocca
thank you kindly!

PostPosted: Sun Mar 30, 2008 8:12 am
by Lyberodoggy
You are welcome...

PostPosted: Sun Mar 30, 2008 10:28 pm
by Tony_LaRocca
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

PostPosted: Mon Mar 31, 2008 11:46 am
by Lyberodoggy
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...

PostPosted: Wed May 21, 2008 9:22 pm
by mercedes
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..!~

PostPosted: Fri May 23, 2008 2:21 pm
by Chromegloss55
Another superb tutorial... :)
_________________
how to make hash

PostPosted: Sat May 24, 2008 9:59 am
by Lyberodoggy
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.

PostPosted: Sat May 24, 2008 5:00 pm
by mercedes
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...~

PostPosted: Sun May 25, 2008 3:38 pm
by Lyberodoggy
If you didn't have any probs while debugging, then there's nothing to worry about.

PostPosted: Sun May 25, 2008 11:47 pm
by mercedes
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..!~