A little bit ago I talked about a library puzzle, in which I set up a bookcase system where each case would remember what book was stored inside it. Turns out, this is useful for way more than books. Let’s talk about a music puzzle in Vidar.
The core concept is this: on activating the puzzle, 7 flames appear, one for each note in a minor scale. There are 10 torches placed around the room. The player will have to select one of the notes and “load” it into the torch. After all 10 torches are lit, we’ll play them in order. If at any time the notes aren’t correct, we’ll play a buzzer and led the player correct it.
We need some sound assets for this – each individual note, and the music we want the player to match. After that, we can do this pretty easily.
Making the Notes
Like with the bookcases, we need to have a single variable that we use to identify what note-flame we’re interacting with. So each flame’s logic looks like this:
The common event is equally easy, just asking the player if they want to carry that note with them. If they do, take the # of the note-flame we approached and put it in our lantern (our way of carrying this magical musical fire).
Making the Torches
Each torch is going to have 3 pages – unlit, lit, and different colored. We’ll use the last one only as an animation when we’re checking to see if all of the torches are correct.
Like with the note-flames, like with the bookcases we need to see what torch we’re selecting. Here we can’t just do 1-10, because each torch needs its own variable. So torch 1’s variable here is 82. We’ll set our “selected torch” to 82.
The common event is also a little more complicated. We need yet another variable – the content of the torch. So, just to distinguish what’s happening here:
- Variables 82-91 are assigned permanently to a torch. Whatever note is in Music Torch 1, that is if Music Torch 1 is currently set to the note “B”, the value of variable 82 will be “2”
- Variable 92 gets set dynamically as we interact with a torch. So, if we interact with Music Torch 1, it will automatically set Variable 92 to “82” – the variable which represents its contents.
- Variable 93 gets set by the common event to the content of the variable represented in 92. So since Variable 92 is “82”, Variable 93 looks at Variable 92 and finds “2.” Variable 93 is then 2.
Why all these variables? It allows for abstraction. All each torch has to do is set Variable 92, and call the common event. That’s it. That’s bug free. Imagine if we didn’t do these things, and just had each torch responsible for itself. If there was a bug in our logic about storing and retrieving the notes, and we had copy/pasted that logic into each torch, we’d have to fix it 10 times. That’s a mess. Don’t do that.We’ll examine the common event “Play a Note” in a second. The conditional branch asks if there’s anything in your lantern. Skip to the else if there isn’t – we’ll ask you to choose a note first, otherwise there’s nothing for you to really do. If there is something in your lantern, ask if you want to put it in the torch (we’ll ask slightly different questions based on whether there’s something already in the torch, but that’s just flavor text).
If after all that, the player decides to put the note into the torch, we’ll backtrack from variable 92 to figure out what torch we’re talking about. That variable will get assigned whatever is in your torch. And we’ll call play a note, this time with the new note.
Got all that? Let’s play some music
Play The Notes
The play the note common event is actually really simple. Right before we call it any time, we set variable 93 to the note we want to play. Then it’s just a simple matter of conditional branches. A lot of conditional branches.
In our torch common event we call this twice. Once when you interact with a torch (to play you what note it is currently holding), and once when you place a new note in (to play you what you put in).
We’ve now got a system that allows us to grab music notes from flames and add them as we want to torches. They can be replaced at will. And the torches all remember what note they hold. Next week we’ll talk about how to play and check the solution!