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.

Comments on this entry are closed.

  • Anja

    I did one thing different when I redid your switch puzzle … instead of resetting all variables by themselves, in case the player gets the wrong sequence, I reset the whole range of the variables (switch variables plus count variable) at once. Makes it slightly more streamlined, I think.

    • Nick Palmer

      Ahahaha, ha, ha, ha, hahaha how did I miss you could do that. I’m a dumb dumb. (17 years and still learning)

      Seriously, every time I write a tutorial, I miss one very obvious thing. It’s a great learning experience for me as well!

  • KSinny

    I’m admittedly a little slow when dealing with text on a screen when it comes ot tutorials, so I’m still trying to wrap my head around how this setup forces you to use the correct Order. Like if I hit Red, then Green first, what part, or parts, of the event actually dictactes that being wrong?

    Additionally, is there a way to run this setup but if you get the incorrect order, it resets immediately rather than waiting until you flip the very last switch? Say if I’m using this setup as an example, the player hits red, then blue first. Cue reset.

    This would be helpful for a puzzle I’m making because it involves running a fair distance between the switches (with monster encounters along the way) and I’d hate to frustrate the players with running between all four, getting it wrong then having to attempt again. I’d rather they know that they messed up the second they hit the wrong switch.

    Looking forward to a response, I’ll keep trying to wrap my head around this setup in the meantime. Thank you.

    • When you are flipping the switch, you first raise the number flipped variable by 1, then immediately follow by assigning that variable to the switch order variable.

      So when you flip your first switch, the flipped variable = 0+1 = 1. You set the switch order variable to = the flipped variable, so it is now also = 1.

      The next time you do this, it changes the flipped variable an additional 1, to 2, And then dumps that number into the switch order variable of that color.

      If you wanted to reset it on EACH switch, just have it check if that switch has the right order number immediately after doing it, if not, do the full reset.

  • Kyle Carmean

    This looks like you can open the door with any order of the switches because each variable adds 1 and when it reaches 4 the door opens. How do you make it open in an order like 1, 3, 4, 2 and if the wrong switch is pressed it all resets. I think that is what you are trying to show here but I just don’t see the part where it resets if the order is wrong. After all the variable called Red switch Order doesn’t put anything in order that is just a name.

    • Touchfuzzy

      When the last switch is flipped, it makes sure that all the variables were stored are what they are supposed to be. If they aren’t, it resets all of them.

      The last image and the paragraph directly under it explains.