Piano Mini-game?

So my game has this section in it with a piano. What I want to do is make it so when the piano is activated the player has piano keys that appear on the screen (or some other buttons). By clicking on them, or tapping (important as this will also be an app), they play sounds like a piano; but if a certain pattern is played it opens up a secret door. Currently I have it set up as a regular press enter -> switch flips -> door opens kind of event. Every attempt I have made to make this work with a mini-game has failed...


Anyone able to explain to me how to do such a thing, or help me figure it out? 🙂  
One way i can think of without having to write a plugin for the window, buttons and such would be using choices.


One example:

Spoiler
Loop


Show Choices: C, D, E, F, G, Cancel


 * C :


       *Play sound*


       if variable 1 = 0 then


          variable 1 = 1


       else


          variable 1 = 0


 * D :


       *Play sound*


       if variable 1 = 2 then


          variable 1 = 3


       else


          variable 1 = 0


 * E :


       *Play sound*


       if variable 1 = 1 then


          variable 1 = 2


       else


          variable 1 = 0


 * F :


       *Play sound*


       if variable 1 = 3 then


          variable 1 = 4


          jump to label: Loopbreak


          *Secret door opens if variable 1 is 4


       else


          variable 1 = 0


 * G :


       *Play sound*


       variable 1 = 0


 * Cancel :


       if variable 1 = 4


          jump to label: Loopbreak


       else


          variable 1 = 0


          jump to label: Loopbreak


End-Loop


Label: Loopbreak

which then would result in a combination of: C, E, D, F


if this would be pressed in the correct order, the secret door would open, else it just resets the variable to 0 and the player had his fun playing sounds :3
Helpful! Thank you!   I don't have a sound puzzle but now I have a reference for making a unlock loop puzzle of any kind. For folks that are new to eventing this is great to see.
I don't know about the clicking/tapping (you might need a plugin that lets you click on pictures), but for the basic unlocking mechanic I would push the keys into an array and then compare it with the sequence you want to unlock the door. It involves some simple scripting, but nothing that needs a plugin on its own. I only really know how to do events, not scripting, so there may be even better ways to do this, but this is how I would do it...


If it's a sequence of 7 notes, you could set up 2 arrays plus a regular variable like this:


var sequence = ["a","b","c","d","e","f","g"];
var playedkeys = []; //empty array
$gameVariables.setValue(1, sequence); // store the sequence in Variable 1
$gameVariables.setValue(2, playedkeys); // store the played keys in Variable 2
$gameVariables.setValue(3, 0); // counts the number of correct keys played (optional)


Every time you touch a key, it does this (for example, the C key)


var playedkeys = $gameVariables.value(2); // retrieve the played keys array
playedkeys.push("c");
$gameVariables.setValue(2, playedkeys); // updates the played keys array

// everything below this is optional

var check = $gameVariables.value(3); // time to check if the key played is the right one.
var sequence = $gameVariables.value(1); // need to load the sequence again

if (playedkeys[check] == sequence[check]) {
check += 1;
$gameVariables.setValue(3, check); // update correct keys variables
} else {
check = 0;
playedkeys = [];
$gameVariables.setValue(3, check);
$gameVariables.setValue(2, playedkeys); // boo, pressed the wrong key. start over.
}

// everything above this is optional

var is_same = (playedkeys.length == sequence.length) && playedkeys.every(function(element, index) {
return element === sequence[index]; }); //check and see if the played sequence matches with the lock sequence

if (is_same == true){
$gameSwitches.value(1) == true; // unlock the door
}


^ the way this one works is that it will reset back to 0 as soon as you press the wrong key. It would actually be simpler to do it so that it just checks every 7 key presses (you could take out everything marked optional) but it could be a little more frustrating for the player (and you also have to make sure to reset the playedkeys array if is_same turns up false)
hmmm these are some good ideas guys! Thanks a bunch 🙂


I would still prefer the whole tapping/clicking on images approach though... So if anyone can help with that, or even knows an appropriate plug in that already exists, that would be fabulous!


@noctiluca I am not yet very familiar with javascript (I know some C, Robot C, and a small bit of java though), especially within RPG Maker. As it stands Shurutsue's method seems a bit easier to me... Can you explain a little how one would implement your method? 🙂

Original thread: https://forums.rpgmakerweb.com/threads/piano-mini-game.56979/