Simple script for a numerical code

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

Simple script for a numerical code

Postby Skye » Mon Nov 07, 2005 12:55 pm

I'll list the script for checking a 4 digit code - it's simple enough then to cut back the script for combinations with fewer numbers required.

sub Check4DigitEntry (key) 'number pressed, 1st, 2nd, 3rd, 4th of code
If KP1 = 0 and key = fstkey Then
KP1 = 1
ElseIf KP2 = 0 and KP1 = 1 and key = sndkey then : KP2 = 1
ElseIf KP3 = 0 and KP2 = 1 and KP1 = 1 and key = trdkey then : KP3 = 1
ElseIf KP4 = 0 and KP3 = 1 and KP2 = 1 and KP1 = 1 and key = fthkey then KP4 = 1
Else wrongkey = 1
End If
End Sub


How this script works:

First, decide what you want the correct code to be. Load these into the variables fstkey, sndkey, trdkey, fthkey. This is done during initialization when your game first starts.

Next, when the player clicks on a numbered button you need to put in the Advanced Tab the name of the 'check' routine (in this example it would be Check4DigitEntry(key) where key is the number on the button they pressed.

The KP1, KP2, KP3, and KP4 variables keep track of how many buttons the player has clicked on.

When the player clicks on a numbered button, the subroutine checks to see if the player has clicked on a button before (the KP variables) and falls to the appropiate line where it checks to see if the button that was pushed (Key variable passed to the subroutine) matches the number for the code (fstkey, sndkey, etc)
If everything is okay then the variable WrongKey is left as zero otherwise it is set to 1

To finish off the process, I usually have a special button for the player to click on when they think they have the code correct. When they click on this button it calls a separate subroutine:

Sub LockBox1
If KP1 = 1 and KP2 = 1 and KP3 = 1 and KP4 = 1 and WrongKey = 0 then
LockBox1Unlocked = 1
End If
End Sub


This little piece of script checks to make sure that the player clicked on the right number of buttons and that they were all correct. If it finds any problems, it does not make the 'unlocked' variable true.

One very important thing to remember when using this script is to 'zero' the KP variables and the WrongKey variable when the player leaves the frame. You do this in the variables section of the hotspot that lets the player leave the frame ('when player clicks on the hotspot set variables to zero') If you don't, when the player return to try a different code, some of the variables may already be set and the puzzle won't work.

If you want the box or safe or what ever the code puzzle is attached to to open when the player gets the right code then just add an Action.GoToFrame to the script like this:

Sub LockBox1
If KP1 = 1 and KP2 = 1 and KP3 = 1 and KP4 = 1 and WrongKey = 0 then
LockBox1Unlocked = 1
Action.GoToFrame "BoxOpen"
End If
End Sub


Let me know if something is not clear.

Skye
Skye
Expert Member
 
Posts: 325
Joined: Sat Sep 13, 2003 4:19 pm
Location: British Columbia, Canada

Postby Candle » Mon Nov 07, 2005 10:18 pm

Thanks for the tut Skye, I'm still trying to understand it.
But I thank you for doing it.
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 Skye » Tue Nov 08, 2005 5:49 am

Hey Candle,

If there is something you can't figure out don't be shy about asking. It can be difficult to make a tutorial that everyone can understand. We are all different people and what is simple to one person be be utter Greek (with apologies to any Greek member here) to someone else.

Skye
Skye
Expert Member
 
Posts: 325
Joined: Sat Sep 13, 2003 4:19 pm
Location: British Columbia, Canada

Postby Candle » Tue Nov 08, 2005 6:00 am

If you could make a small demo showing something with it working that would be good .
Upload to some free site and give me the and I'll put it on my server.
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 Skye » Tue Nov 08, 2005 6:51 am

Great! I'll see what I can do in the next few days.

Skye
Skye
Expert Member
 
Posts: 325
Joined: Sat Sep 13, 2003 4:19 pm
Location: British Columbia, Canada

Postby Skye » Sun Nov 13, 2005 10:02 pm

I made up a little AM project to illustrate how to set up a code box using the code snips I posted above.

You will find the tutorial at:
http://members.aol.com/agre107/CodeBoxTutorial.zip

Let me know if there are any problems or questions.

Skye
Skye
Expert Member
 
Posts: 325
Joined: Sat Sep 13, 2003 4:19 pm
Location: British Columbia, Canada

Postby Candle » Sun Nov 13, 2005 11:46 pm

Thank you , that will help a lot as I can look at how it is done . it is so hard for me to remember stuff now.
I need something to open and look at and go back to when I working on it.
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 Skye » Mon Nov 14, 2005 3:44 am

You're welcome.

I too have trouble remembering how to do stuff. I have so many pieces of paper with techniques and my own personal notes scribbled on them . . .

Oh well, what ever works eh?

Skye
Skye
Expert Member
 
Posts: 325
Joined: Sat Sep 13, 2003 4:19 pm
Location: British Columbia, Canada

Postby Candle » Mon Nov 21, 2005 5:16 pm

I need your help. I sent you a PM.
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 Mystery » Sun Dec 02, 2007 9:06 am

Finally I've understood how this script works 8)
I've adapted it for a puzzle with even 8 buttons, and it works like charm, so thanks for this tutorial Skye :D
User avatar
Mystery
Forum Admin and Games Page admin
 
Posts: 2990
Joined: Sat Feb 04, 2006 8:12 am
Location: Switzerland

Postby Lyberodoggy » Mon Feb 25, 2008 7:26 pm

Skye wrote:Hey Candle,

If there is something you can't figure out don't be shy about asking. It can be difficult to make a tutorial that everyone can understand. We are all different people and what is simple to one person be be utter Greek (with apologies to any Greek member here) to someone else.

Skye


Yeah, I am Greek, but don't mind... We say the same for chinese (we couldn't say it for greek, because it's our mother-language :P)
User avatar
Lyberodoggy
Administrator
 
Posts: 2526
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby Chromegloss55 » Tue Feb 26, 2008 7:54 pm

Nice technique, do you mind if I include it in my 100 Visual Basic Techniques guide? (I'll give you credit of course!)
_________________
chocolate chunk strain
Chromegloss55
Forum Master
 
Posts: 630
Joined: Sat Nov 03, 2007 2:49 pm
Location: God Knows!

Postby Mystery » Sat Dec 26, 2009 9:50 am

Does anyone have this demo?
I had it on my old machine. It's not available anymore from the provided download link :(
User avatar
Mystery
Forum Admin and Games Page admin
 
Posts: 2990
Joined: Sat Feb 04, 2006 8:12 am
Location: Switzerland

Postby Imari » Sat Dec 26, 2009 8:33 pm

User avatar
Imari
VIP
 
Posts: 872
Joined: Fri Jun 20, 2003 4:49 pm
Location: Virginia, USA

Postby Mystery » Sat Dec 26, 2009 8:45 pm

Oh, you have it? :D Thank you very much :)
User avatar
Mystery
Forum Admin and Games Page admin
 
Posts: 2990
Joined: Sat Feb 04, 2006 8:12 am
Location: Switzerland

Postby Imari » Sat Dec 26, 2009 11:49 pm

Mystery, if you get an error message, try again later. A lot of people use Rapidshare to share Xmas photos with family and the site gets too busy for free downloads.
User avatar
Imari
VIP
 
Posts: 872
Joined: Fri Jun 20, 2003 4:49 pm
Location: Virginia, USA

Re: Simple script for a numerical code

Postby igelkott » Tue Jan 06, 2015 6:42 pm

Hello everyone!
I trying to do this script for 4-digit puzzle - does not work without an example, and all the links are dead...
Is somebody has this "Tutorial-CodeBox"?
igelkott
Junior Member
 
Posts: 12
Joined: Sun Dec 28, 2014 10:36 pm

Re: Simple script for a numerical code

Postby reneuend » Wed Jan 07, 2015 2:34 am

Welcome igelkott!

I, personally haven't reviewed this. If you have a few days, I'll review it and build an example or ....


Here is something I wrote that will achieve the same objective and in my humble opinion, is easier to modify for any number of sequences. The post comes with instructions and the project sample.

http://amforums.cloudapp.net/phpbb/viewtopic.php?f=10&t=6080&sid=51772a63a0c25a836050836c55ce1920

Glad to have a new member on the forums. :wink:
---


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

Re: Simple script for a numerical code

Postby igelkott » Wed Jan 07, 2015 8:29 pm

Thank you, reneuend!
I will learn a lesson on this link while waiting for Tutorial-CodeBox.
...It's a very interesting - to make games!
igelkott
Junior Member
 
Posts: 12
Joined: Sun Dec 28, 2014 10:36 pm

Re: Simple script for a numerical code

Postby reneuend » Thu Jan 08, 2015 2:14 am

Here is the Project in a Zip file.
Just add it to your Projects folder for AdventureMaker is located and open it up from AdventureMaker.

http://www.hickchickgames.net/Other/ComboLock.zip

I added a few things:
- sound for key clicks
- sound when safe is opened
- messages
- alphabending and delay to the 2nd frame

I didn't use the LockBox1Unlocked variable, but in a game, you might want to use it if you need to know that the player opened the safe later on in the game.

If you struggle with understanding it, let me know. I'll shuffle you to my solution in the AM Magazine! :wink:
---


Image
Image
User avatar
reneuend
Administrator
 
Posts: 2762
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 0 guests