Golden Week Tutorial: Ordered Switch Puzzle

in Tutorials

To continue our Golden Week Celebration, where you can currently get huge deals on all things RPG Maker, and perhaps win a copy of RPG Maker MV, I’ve also decided its a good time to do a couple of Golden Week Tutorials!

Today, I have a tutorial requested by a fan on Facebook. If I have 4 switches, and they have to be flipped in a specific order, how do I event this puzzle in RPG Maker? I’ll also include a demo at the end.

Now, this is a pretty common puzzle in RPGs and Adventure games. Figure out the order, flip the switches, carry on.

So I draw out a quick map with the events mocked up for it to work with.


The first thing I like to do when creating an event I don’t know how to do yet is break things down by writing down all the information I will need to store. If you think of what needs storing from the beginning you can usually figure things out pretty fast. So in our 4 switch order puzzle, these are the things that need to be stored:

  1. How many switches are flipped?
  2. Is a switch flipped
  3. What order was a switch flipped in
  4. Did the puzzle get completed?

Let’s start with number 3 and go backwards. Number 4 is obviously just a switch: Is the puzzle done. There isn’t any more information but off and on. So that is one switch. Number 3, the order the switches are flipped. That is a variable. One for each switch. Just store 0,1,2,3 in them as they are switched on.

But what about 2? Its obviously switches, and in a lot of cases you would use a self switch for this unless it was being referenced from an outside source, but they aren’t REALLY necessary. Instead, I could just have the variable from 3 have 0 = switch isn’t flipped. So each switch variable is now 0 = not flipped, 1-4 equals order flipped.

The last thing I need is a way to tell when all 4 switches are flipped. Technically I could just check if each of the 4 switch order variables are non-0, but making this its own separate variable will make it easier to store the variables for the others, as you will see shortly. So that leaves me with the following switches and variables:

variablesswitchesThis creates perhaps the simplest setup we can use. Technically, I can think of other ways to do it, some more complex, some more obtuse, but this is probably the ideal setup.

So, the first thing to do is create the first switch event. I’m going to remove all the graphical and audio parts from consideration other than fully on and fully off, because those are pretty simple, and not really part of the challenge of making the event (all it is is move events turning the event to make it look like its switching/opening). What we want to look at is the pure mechanical part of the eventing to understand it.

Now, let’s break down what should happen each time a switch is flipped. Writing down what you want an event to do in plain text makes it easier to conceptualize how it works and what you need to do with it. So this is what we need this event to do:

  1. It should increase the Count variable by 1, to show that 1 more switch has been flipped
  2. It should record the order the switch was flipped in the appropriate switch order variable.
  3. It should check if all the switches are flipped.
    1. If Yes, it should check if the order is correct
      1. If Yes, it should open the door.
      2. If No, it should reset the whole room
    2. If No, it should do nothing.

Number 1 is easy. Just Control Variables Count = Count +1.

Number 2 is also easy, and now you’ll understand why I made Count a separate variable instead of just checking if all the Order variables were nonzero. All we have to do, is set the appropriate Order variable to the Count variable with Control Variables.

So starting with the nested Conditional Branch for #3, we start with If Count = 4 so that you can tell if all 4 are flipped. Then we check each individual variable in nesting to make sure its the right numbers, if it is, switch the Door Open switch to On. Now, we could create an else branch for every single one of the nested conditional branches checking the Order, but that isn’t nearly as efficient. Since if they are all right, it flips a switch, you can instead put another conditional branch under the nested set, but still inside the If Count = 4 to check if the Door Open switch is Off. If it still is, then it resets the puzzle by changing all the order variables back to 0.

This is what the event should look like:


The first section changes Count up 1, then sets the switch order variable. Then if all switches are flipped (4), it checks if the order is right and then if it is flips the switch to turn the door on. Then if all the switches are flipped, and the door is NOT open, it resets the puzzle. Exactly what we needed.

After that, just set a second page that is the switch flipped if the Order variable is 1 or higher for it, and a second page on the door that is open if the Door Open variable is on. Copy over the contents to all 3 other switches, change the variable references in them and color, and bam. Done. You can of course, add in graphical stuff and audio (which I have done in the short demo of this puzzle that you can check out HERE), but the puzzle fundamentally works on a mechanical level here.

So, can you think of another way to do this? Maybe with less variables? Or maybe with shorter events? I actually have a more obtuse way ruminating in my head that uses less variables, let’s see if you can think of it. There is also part of the event that is duplicated that doesn’t actually need to be. Or maybe you have a question about the way I did things? Join us in the comments below.

6 comments… add one

Leave a Comment