Making a "Press Buttons in Correct Order" puzzle

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
44,192
Reaction score
15,545
First Language
English
Primarily Uses
RMMV
This is the kind of puzzle where you have 4 buttons in a room and you have to press them in the correct order, to open a door or give some other reward. There are already a few tutorials out there, but this is a nice simple one, requiring just a single switch, a variable, and a common event, in addition to your button and door events. It would be easy to modify the instructions below to use up to 9 buttons.

I will give instructions for two versions of the puzzle. In one, the player has to press all 4 buttons before they find out whether they solved the puzzle or not. In the other, the puzzle will reset as soon as an incorrect button is pressed. Steps 1 and 2 are the same for both versions.

The screenshots below are from Ace, but I will point out where you need to do something different for MV, XP, or 2K/2K3.

Overview

Here's how it will work. Each button will have a different number allocated to it. We will track the button sequence in a single variable. Each time a button is pressed, the variable will be updated by moving all the digits to the left and adding the number allocated to that button.

If the player presses the buttons in the correct order, the variable will be set to 1 after the first button, 12 after the second button, 123 after the third button, and 1234 after the fourth button.

PushbuttonPuzzle01.png


Step 1 - create your first button

Create the event for your first button. On tab 1, set the sprite to the out/off image. On tab 2, set the sprite to the in/on image. Add your commands to tab 1.

If you want your button to animate, start off by setting a move route to turn left, then right, then down, with a brief wait in between (this is like the door and chest quick events). If you have your events set to Direction Fix, make sure to turn that off at the start of the move route, and then on again at the end. Set the move route to wait for completion.

Now turn on self switch A. RM2K/2K3 doesn't have self switches, so you will have to use a regular switch. VX Ace Lite has self switches, but no access to the script command, which we need later, so use regular switches if you have Ace Lite.

Change the variable you're going to use to track the button sequence. First, multiply it by 10, to move all the digits one place to the left. Then add 1 to the variable. When you start a new game, this variable will be 0. And when we reset the puzzle, we'll change it back to 0 again.

Finally, call a common event that will contain the logic to see if the puzzle has been solved, or needs to be reset. We'll create that in a few minutes.

On tab 2, set the condition to self switch A. RM2K/2K3, Ace Lite will use the switch that you turned on in tab 1.

PushbuttonPuzzle02.png


Step 2 - create the rest of the buttons

Now that your first button is done, go ahead and copy/paste it for each additional button in the puzzle.

Go into each one and change the graphic on both pages so they are different coloured buttons (if you want them all to look different), and change the number you add to the variable, so each button adds a different number.

To make it easy, my buttons are numbered 1, 2, 3 and 4, and they must be pressed in the order 1, 2, 3 and 4, and those are the numbers that get added to the variable for each one. I can move around the events in the scene as much as I want later, but it's easier to just create them in the order they should be pressed.

RM2K/2K3 and VX Ace Lite will also need to change the switch being turned on in the tab 1 commands, and the switch used as a condition in the tab 2 commands. Make sure each button uses a different switch.

Step 3 - create the "puzzle solved" common event

The first version is where the player will only know if the puzzle is solved after pressing all the buttons. So we only want to do something if all buttons have been pressed. This means the variable will be 4 digits long, so > 1000. For each extra button, there will need to be an extra digit, so an extra 0.

If the variable is > 1000, check to see if it represents the correct button order. In my example, buttons must be pressed in the order 1, 2, 3 then 4, so the variable should be 1234. If it is, give the player the reward - turn on the switch that controls the door, or the chest. If the sequence isn't correct, we'll reset the puzzle. This means setting the variable back to 0 to start again, and resetting all of the buttons. XP, VX, VX Ace and MV can do this with a Script call to change the self switches, passing in the map and event ids, with no leading zeros, and the self switch id. 2K/2K3 and VX Ace Lite don't have a Script command, so they will just turn off all the switches that control the buttons.

The second Else in the screenshot below is unnecessary - feel free to leave it out.

PushbuttonPuzzle03a.png



The second version is where the puzzle will reset the moment the player pushes a button in the wrong order. In this version, there is one correct value for the variable (1234) that will solve the puzzle, three on-the-right-track values (1, 12, and 123) where we won't do anything, and every other value means they've pressed the wrong button, so we'll reset the puzzle.

So first, do the test to see if the puzzle is solved. If the variable shows the correct sequence, 1234, turn on the switch to indicate the puzzle is complete so the player can get their reward. Otherwise, add a series of conditional branches to make sure the variable doesn't hold one of the other 3 values. If it is not any of those values, reset the puzzle, following the same steps as above.

PushbuttonPuzzle03b.png



VX / VX Ace - use the commands as shown in the code above:
Code:
$game_self_switches[[1, 1, 'A']] = false
$game_self_switches[[1, 2, 'A']] = false
$game_self_switches[[1, 3, 'A']] = false
$game_self_switches[[1, 4, 'A']] = false

The first number is the map id, the second number is the event id, and the character is the self switch id, surrounded by quotes. Do not put leading zeros on the map or event ids.

XP - do the same as above, but add this at the end:
Code:
$game_map.need_refresh = true

MV - is slightly different:
Code:
$gameSelfSwitches.setValue([1, 1, 'A'], false);
$gameSelfSwitches.setValue([1, 2, 'A'], false);
$gameSelfSwitches.setValue([1, 3, 'A'], false);
$gameSelfSwitches.setValue([1, 4, 'A'], false);

2K/2K3 and VX Ace Lite - there is no Script command, so just turn off the switches for each of the button events.

VX, VX Ace and MV may have an issue with the button image not resetting when you reset the puzzle. If that happens, add a Move Route in the common event, for each button, with the command Turn Down.

Step 4 - the reward

Of course, there will probably be another event, maybe on this map, maybe on another, that is conditioned by the "puzzle solved" switch. It could be a door, or a chest. Or it could be something that happens straight away (like a spirit that appears and gives you the ultimate weapon) - in that case, you could put the reward straight into the common event rather than using another event that the player has to locate.
 
Last edited:

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,973
Reaction score
3,096
First Language
French
Primarily Uses
RMMV
oh damn I remember those kind of puzzle XD this was the first I tried to do with my game haha! it was not optimized like yours though!
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
44,192
Reaction score
15,545
First Language
English
Primarily Uses
RMMV
wow - I think I just came up with a way to super-simplify that.  Got to test it and update the tutorial.


edit - yep - so much easier.
 
Last edited by a moderator:

Latest Threads

Latest Profile Posts

Where would you go if you're looking to hire someone on here? I'm in need of a writer to take my story concept and turn it into npcs/dialog in my game.
Evening humans! How goes the game make?
The anime characters we saw 20 years ago,
still have the same age when we see them now.
Somehow it's strange but also beautiful.
It's like no matter how much we change,
there's certain part of ourselves we can reconnect to when we see them again.
Took a long, long time, way longer than it should to be honest...but I've finally finished the big content update to my demo!

Forum statistics

Threads
117,256
Messages
1,105,892
Members
153,422
Latest member
Gl7
Top