• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Audio

So I don't know much about the audio system. I know I have 48 stages, each with its own music. Now I have a store where the player can purchase gems. The store has its own music. So if you click on the coin icon it takes you to the store, the music changes. Now I want to be able to return to the game and switch back to the previous room's music. How do I go about that? I thought about setting a variable when I do the audio_play_sound but that means I would have to have 48 variables to code by hand. Actually 96 lines code since I have to change the initial audio_play_sound and then I have to change the music in the store back to the room's music. There has to be a more efficient way to go about this.

Thanks
Ted
 

Nidoking

Member
I have a Controller object handle the music. In the Room Start event, I check whether audio_is_playing(Music) and, if not, I stop the current music and play the Music variable. Then, in each room's Creation Code, I set Controller.Music to the music for that room. So each room handles its own music automatically.
 
I do the same as @Nidoking except without the controller object. Let you room determine what music should be played, and in the Room Start stop all other music and start the one for the room. It's basically 2 lines of code in each room, and does not require 48 variables.

Alternatively you can set up one global variable for previousMusic, and when leaving the room to go to the store you set the variable to be the music that you want to play when it leaves the store, and then when leaving the store just play the music resource that is in previousMusic.
 
I do the same as @Nidoking except without the controller object. Let you room determine what music should be played, and in the Room Start stop all other music and start the one for the room. It's basically 2 lines of code in each room, and does not require 48 variables.

Alternatively you can set up one global variable for previousMusic, and when leaving the room to go to the store you set the variable to be the music that you want to play when it leaves the store, and then when leaving the store just play the music resource that is in previousMusic.
That's what I need to know. How do I save a sound in a variable? So I can do this:

room_music = somehowgettheaudioplayingrightnow
goto store room
music = store music
goto back to first room
music = room_music
 
room_music = somehowgettheaudioplayingrightnow
You don't need to get the music that is currently playing. Both @Nidoking and I have already suggested:
Then, in each room's Creation Code, I set Controller.Music to the music for that room.
Let you room determine what music should be played, and in the Room Start stop all other music and start the one for the room. It's basically 2 lines of code in each room, and does not require 48 variables.
The simplest answer is just to put into the Creation Code of each room:
Code:
audio_stop_all();
audio_play_sound(yourMusicResource, 10, true);
That's it, and you would do exactly the same in the store room as well. Now if your rooms are all persistent then you would have to use a different method as the Creation Code would only be called the first time that you go to the room. But as you haven't said if they are or not, you might just be able to get away with the above. Even if you are going to use the controller, or the global variable for the previous music, you still don't need to try to figure out what music is playing - you would just set the variable to a music resource and then use that for the audio_play_sound call.
 
Last edited:

Nidoking

Member
If you do want to save a sound in a variable, you don't do it while it's playing. You store the return value of audio_play_sound. That's the specific sound you would need to stop.
 
Top