Tutorial: Insert Button Sequence

in Tutorials

It is time for another quick eventing tutorial! Our last two covered flipping switches in the right order and pressing a button quickly when given a prompt. Today, we’ll cover making an event where pressing a combination of keys in the proper order does something in the game.

You can find this puzzle in plenty of games, such as entering the password to save Lucca’s mother in Chrono Trigger, playing the piano in Tifa’s old house in Final Fantasy VII, as well as a similar music-based puzzle in Undertale.

It goes like this: You are given a sequence of letters/sounds/notes to play, and each one is tied to a specific key on your input. You then go up to the event, press the keys in the proper order, and voila, you get something/advance the plot/whatever.

For this tutorial, I’m going to create an organ that when you play the notes in a certain order, you find a potion. Unfortunately, there are no individual music notes in MV’s default sounds, so instead, this organ, as designed by Bloody Stupid Johnson, makes animal noises.

It is particularly useful for playing Old MacDonald though.

It is particularly useful for playing Old MacDonald though.

In the map above, the note to the left tells you what keys make which noises, and the order from left to right of the animals is the proper order to play them in. Now, I know that this is not a hard puzzle for the player to solve but learning the eventing to make it work is the key here, not making a tricky puzzle. Here are the key commands:

  • Up = Chicken
  • Down = Cat
  • Right = Horse
  • Left = Dog

And with the order being Dog Cat Chicken Horse, the proper sequence is Left Down Up Right.

So once again, as with our previous eventing tutorials, the first question is: What information do I need to be able to store and access? This is a pretty simple list for this event.

  1. The Button Press order
  2. Whether you have gotten the potion or not.

The second one is just like a standard treasure chest, which is just a self-switch. This is always nice because that means we don’t have to clutter up the global switches/variables with it. The first one will require a variable because each step has 4 different options. Now, you may be thinking you need 4 variables, but I have a much easier method to use just one. I’ll show you how to do this as we make the event.

variables

It doesn’t get easier than this.

The next step is to, in plain speak, walk through what you want the event to do.

  1. Wait for player to press a directional key.
  2. Record key pressed
  3. Repeat steps 1-2, 3 additional times.
  4. Check recorded key presses to see if it matches the correct order
    1. If Yes, give the player a potion, and switch the event to permanently off, end event processing.
    2. If No, reset the recorded key presses and end the event processing.

Waiting for a keypress is another good time to use a Loop, just like we did in our last tutorial. Create a loop, and have it break the loop when one of the four keys are pressed using conditional branches. Let’s go ahead and throw the sound effects in there too.

But what does the fox say?

But what does the fox say?

I’ve added a 30-frame wait command to make sure my loop isn’t starting too soon. This keeps it from catching any input the player happens to be holding when the event starts. You can copy the Loop + the Wait 30 frames 3 more times to get it to record the info 4 times. But how do we record all the information into one variable?

So each time we record the variable, why not, instead of using the set option to change it to a specific number, we use the add function on each step.

Add

There are 4 steps. So during the first step, add 1000, 2000, 3000, or 4000 depending on the button pressed. During the 2nd add 100, 200, 300, or 400, the third 10, 20, 30, or 40, and during the final, 1, 2, 3, or 4.

This will give you a unique 4-digit number that is different with each input combination your player can make, as the steps never overwrite each other. A short section of the event would look like this:

This is the first loop.

This is the first loop.

With all the recording done, all that is left is the final bit of conditional branches to either give the potion or error out and reset the whole puzzle, and that is a snap. Make a conditional branch to check if your key sequence is correct (in my case Key Sequence should = 3214) In the conditional branch, just do the normal treasure chest style stuff. In an else branch, have it reset the puzzle by returning the Key Sequence variable to 0.

Nothing to it.

Nothing to it.

The last thing is to make the second, blank page that has the condition of “if Self Switch A = ON”, and you are done. Want to see the full event? You can download the demo here to get a look at the whole process!

So, this time, I’m going to give you a little homework for you to talk about in the comments:

  • If given one extra variable to work with, could you make this event run in fewer lines of event code?
  • Could you do the entire event with just one switch and one self-switch and not even use a variable?

Want to discuss the homework? Think you’ve figured them out? Or maybe you know another way to shorten this event? Have questions on how to implement something similar in your game? Join us in the comments section below.

Comments on this entry are closed.

  • William Johnson

    Challenge accepted.

    • Nick Palmer

      Good luck.

  • Kurisu Simon

    Your on nick

  • Kurisu Simon

    It’s go time

  • Nick Palmer

    Still waiting on the people trying the challenge section: I have both already done in a new demo. Even did the whole event without a single global variable/switch.

    • Julien Ossola

      Good, now do some good and share 😉