Last week we discussed how to create a set-up where a player can load “notes” into torches, such that each torch remembers its note and can play it back accordingly. Now we want to test the solution. Tale of Two Arrays To do this, we need to create two arrays.
- sound_array, which is the names of our sound effects in order. So, for me, it’s [“A-bell”, “B-bell”, “C-bell” … etc.]
- correct_array, which is the index into that array of all the correct answers. Something like [3,6,8,2,1…]. Basically, converting your solution into numbers which index to sound_array
Stop and Go When the player checks the solution, we want them to hear the notes, and if one is wrong, stop playing immediately. I use a while loop. Just as before, I set variable 93 – our “play this note variable” – equal to whatever is stored in the first torch. I’ll set the self switch of that torch on just to change the animation. I’ll use that torch’s note as an index into sound_array to play the sound effect. And if it doesn’t equal the right number in correct_array, I’ll play a buzzer and break. Then we’ll wait 90 frames, and do all of that again with torch 2. If we finally make it to the end, we’ve won!
if $game_variables[torch_id] > 0 RPG::SE.new(sound_array[$game_variables[torch_id]-1], 100, 100).play if $game_variables[torch_id] != correct_array[torch-1] wait(30) RPG::SE.new("Buzzer1", 50, 100).play break end end
This is just a snippit of the code, but it gives you the core idea. You see a few “-1″s in there. There’s an off-by-one-errors in all of this, and that’s because we need to be able to represent no-note. If a torch has note A, you’ll recall from last week’s post that we store the integer “1” into its assigned variable. Except if I try to find A-bell in the sound_array, it’s at position 0. We just need to be careful of that as we go through our logic. The end result? Well check it out in the video below!