Games Music Puzzles (Read 272 times)

  • Group: Member
  • Joined: Sep 10, 2003
  • Posts: 9
I have an idea for a music puzzle in RMXP but I can't wrap my head around the coding. The idea is basically this:

The player hears a brief tune broken down into three music files. The player is expected to play the tune in the same order heard in order to solve the puzzle. The puzzle has three parts, and the game should detect whether or not it was played in the correct order when all three inputs are finished. If possible, the song can change order to prevent mindless trial and error.

I originally planned to turn it into a mathematical problem. Each part of the tune would adjust a variable through addition, subtraction and multiplication. If the tune was played correctly, and if the variable ended up at the set result, the player would pass. If the tune was played incorrectly the variables would add together to make an incorrect number and reject the player. I don't think this would work, however.

The other option would be to use conditional branches and create a massive amount of branches to accommodate every combination of notes for the tune. If more parts of the tune are added, or if there is a randomized element to the way the tune must be played, it would create a confusing web of code.

Is there an easy way to make this work or am I over-thinking it?
  • Avatar of AdderallApocalypse
  • Five foot ace of clubs?!?!
  • PipPipPipPipPipPipPip
  • Group: Member
  • Joined: Mar 16, 2007
  • Posts: 1086
Setting a puzzle up in this fashion shouldn't require much effort, actually, and If you want to add a little bit of variety by switching up the order of the tune from time to time, then I would begin with a simple variable set to a random value between 1 and  6 - 6 being the number of ways to assemble the tune if there are three separate pieces assuming that each piece isn't repeated(there may be some bad math here but adjust accordingly). Let's assign each individual tune a variable and, depending on how the tune is played based on the random variable, each tune is assigned a value of 1 to 3 which corresponds to it's order in the whole tune. Now we can create three separate variables for each individual input in the puzzle, in which there are three choices. Now here comes the part that is a little bit more tricky: Each time the player selects a piece, you have to set the value of the input variable  equal to the order in which it is played and, to do this, each one has to check whether or not the others have been played yet. I would assign a switch to indicate where the player is in the puzzle by turning one on after each choice, and a line of code that checks whether the previous switch is on and, if so, turns the next switch on - so on and so forth until completion. Once the player has chosen their order, you could use conditional branches to check if each input variable is equal to the preassigned value of that piece. In theory, I believe that this method would work, but I haven't actually put it into practice yet and, to make matters worse, I'm only trying to visualize the puzzle without any actual experimentation. But read this and try to implement it, and let me know how it pans out. Good luck!
  • It's coming along nicely...
  • PipPipPip
  • Group: Premium Member
  • Joined: Nov 30, 2005
  • Posts: 384
There is a really easy way to do this: switches.

Say it was 3 notes they had to play in order (for simplicity sake). Lets also say you are using bells to make the notes, also for simplicity sake.

Make three bell events and associate each with a different tone. Now, for every note that needs to be played you have to have a switch. So if the player just needs to play three notes in order, then you only need three switches. This is the example I'm going to start with.

If you were to only use a three note song, this is what the first bell would look like:



Regardless, when the event is activated it will play the first tone (I used a Note instead of play music, get it? haha, I'm lame... moving on.)
The easiest way to program this without getting confused is to think of the correct tones being played in order. Tone 1 played first, tone 2 played second, etc.

The first fork condition is checking to see which notes have already been played in the right order. Because this is the first note, you want all the switches to be OFF. If any of them are on and you are playing this note, it will turn them ALL off. In other words, if the wrong note is played then the sequence is reset. Because the same tone is always played when the event is activated, the player doesn't know this (unless you play a different tone when they screw up. I don't recommend this as it makes things too easy.)

To recap the above, the first fork conditions are essential to this sequence. If you have 10 notes played in the sequence, then you would have 10 fork conditions here. There is an exception to this which I will explain later.

Okay, so if you are playing three tones using three notes then you would copy this event and make bell 2. There will only be 3 changes made. The first  fork condition should be "tone 1 correct" - ON instead of off. The sound played would be changed. The first switch would turn on "tone 2 correct" instead of turning on tone 1 correct. Voila, you have your second bell. Copy this again and make the appropriate changes for tone 3. When "tone 3 correct" is turned on, then the player has solved the music puzzle. You'd use this switch to give them whatever reward you have planned.

You obviously already have another event that plays the tones in order to tell the player what to play. Now all you have to do is mix up the bell events so it's not a simple 1, 2, 3 for the player.

So that was a simple way of putting it. You could make it 20 tones long if you wanted, just apply the same principle.

Now if you want to make it complicated, and I know you do, then you'll want some tones to play more than once. NO PROBLEM!

Say you have 3 bells again, but you want them to play 5 tones. Lets give it this tune:

1, 3, 2, 2, 1 : tones (even though it's only 3 tones, 5 switches are needed)
1, 2, 3, 4, 5 : switches

The same principle will apply, except that bell 1 and bell 2 will have a second page each. When the tones are played in order 1, 3, 2, then the third switch will be activated. This third switch will be what activates page 2 of bell 2. If the note is played again making the order 1, 3, 2, 2 then switch four is activated turning on page 2 of bell 1. If that note is played then switch 5 is activated.

There are three ways to make this more complicated:
Add more bells (harder for the player), or
repeat the tones often (more confusing to program), or
do both, making it really challenging for both of you.

Before you start, decide how many bells and tones you want to play so you can plan it out. Personally I suggest making 4 bells with about 6 tones. This will make it challenging for the player, but it shouldn't be annoyingly so.

If you want to have this type of puzzle in your game, I suggest placing it in more than one place. Instead of using bells you could use cords or whatever else. When the player finishes the puzzle it could activate another switch which renders those bells useless (a new page that only plays the tone, but doesn't do anything to switches. This page activated by the last switch.) Doing this will allow you to copy all the events for a different are and make a new puzzle with very little effort. You could use the same switches again, just change the sounds and move the events in a different order.

Wowzers, I might as well post this in the tutorial section now...
Sweet online game in alpha.
http://trisphere-rpg.com/index.php?refer=bucchus
  • Group: Member
  • Joined: Sep 10, 2003
  • Posts: 9
Yeah, that is a pretty hardcore guide. Thanks guys, I'm definitely going to try this out. Puzzles like these are superior to your standard "push the rocks" puzzles that are common in RPGmaker games.

I still have to wrap my head around everything, but I know I can figure it out once I start getting my hands dirty.
  • It's coming along nicely...
  • PipPipPip
  • Group: Premium Member
  • Joined: Nov 30, 2005
  • Posts: 384
Trust me, if you can figure out the first two bell events, it will come simple. Since I posted this, I've nearly completely implemented my own 6 tone puzzle (thanks for the idea, haha.) The only thing I have left to do is make the music and the NPC that initiates the task.

Remember to write out the way you want to put it down first. If you're using 6 tones (recommended) and 3 "bells," design the tune first. For example:

The tones (bells) might be played in this order:

1 3 3 2 1 2

The switches will still be

1 2 3 4 5 6

You'll have this in no time. :D
Sweet online game in alpha.
http://trisphere-rpg.com/index.php?refer=bucchus
  • Group: Member
  • Joined: Sep 10, 2003
  • Posts: 9
Although this response is a bit late, I implemented this puzzle and noticed a few important things.

Following the steps provided in the puzzle, I found that I couldn't get it to work. The source of the problem was the way the switches were being activated. It would turn on the first switch for the first note and then turn it back off immediately. I removed both sets of "Change Switch X: OFF" from under the END cases and it fixed the problem.

Basically, I made it work by only turning off switches in the ELSE cases. I'm pretty sure I copied everything in the guide correctly, but who knows. Either way, it's working and the guide was a huge help.

If I could add something to the guide, it would be a variable to initiate the music playing event. At the start of each bell, place a variable+1 command. Every time a bell is played, it adds 1 to a variable. When the variable reaches 3, an event checks to see if all switches are on and resets the variable back to 0 if not. To illustrate:

Player reaches the room with the music puzzle.
Player starts the music event (pulls switch/talks to NPC)
Player hears the tune
Player attempts to play the tune using the 3 notes
If the 3 notes played are incorrect, the player is notified and the event restarts
If the 3 notes are played correct, the player continues the game

With a variable at the start, the player could not only get incorrect combination of notes but they could also hit the same note 3 times and still get a notification. I believe this helps make the puzzle less confusing since the player will know how many notes have to be hit in order to pass the test. Perhaps someone else could word it better...

Thank you again for the help! I wouldn't be brainstorming about this otherwise.
  • It's coming along nicely...
  • PipPipPip
  • Group: Premium Member
  • Joined: Nov 30, 2005
  • Posts: 384
When I tested the puzzle I found the same problem, haha. Yes, it was as simple of a solution as taking out the extra turn off events. I figured if you had a problem you'd say so and I'd correct that.

As for how you want to let the player know how many notes to play, there are a couple ways of implementing it. I made a mini-quest/game out of this. There is a bard that lost his harp and is now using jugs. However, to play a jug you have to be blowing on it, making it impossible to sing at the same time. So he requires that you blow on the jugs while he sings you a song. He whistles the tune of notes that he wants which is a vocal cue to the player. The puzzle being that the player needs to be able to pick out the three tone changes. It makes it difficult, but it also tells the player how many notes are needed. The bard will replay the tune he wants as many times as the player needs.

To keep the player from activating the bards song before talking to him I simply added a page on each jar event that only plays the note but doesn't activate any switches. Once the bard asks you to play a tune for him a variable is added to the second page which works like the above tutorial (minus the extra switch offs).

There is actually a number of ways this all can be done. To me this just seems to be a relatively simple way of doing it.
Sweet online game in alpha.
http://trisphere-rpg.com/index.php?refer=bucchus