GameMaker: Studio

GameMaker: Studio

View Stats:
How to stop repeating music on death!
I have nice background music for my game and when the walls of the maze are touched the maze restarts however the music doesn't which is a good thing however the music will play the song from start over the original song. so i have 2 background musics playing at the same time. Anyone know how to solve this?
< >
Showing 1-15 of 15 comments
Püloo Cthulhu May 2, 2016 @ 8:20am 
Last edited by Püloo Cthulhu; May 2, 2016 @ 8:20am
Blind May 2, 2016 @ 8:23am 
On your death event... and via the keyboard
Püloo Cthulhu May 2, 2016 @ 8:25am 
Originally posted by BBX:
On your death event... and via the keyboard

Dude i am super new lmao, i'm just making a maze game for my assignment. i didn't even know programming was a part of game maker until you mentioned it. how would i open the code i need
Blind May 2, 2016 @ 8:41am 
ahh, all programming aspects are handled by the Excecute Code action, I think it's on the 4th tab, but y'know - I don't know off the top my head, just look for it.

basically wherever you are causing a death to happen, you would make sure to stop the audio first.

Alternatively, at the start of your room - stop all existing audio
Püloo Cthulhu May 2, 2016 @ 8:52am 
Originally posted by BBX:
ahh, all programming aspects are handled by the Excecute Code action, I think it's on the 4th tab, but y'know - I don't know off the top my head, just look for it.

basically wherever you are causing a death to happen, you would make sure to stop the audio first.

Alternatively, at the start of your room - stop all existing audio

Okay so how do i actually do that. I pressed the button with "execute" on it and it just made a version of my game. i tried to edit it then with notepad++ but it was all encrypted. Am i on the right tracks or am i doing it completely wrong?
Blind May 2, 2016 @ 9:00am 
No, that's wrong - the button is in the action menu of an object, where you have the tabs like Main 1, Main 2, and so on.
Püloo Cthulhu May 2, 2016 @ 9:15am 
Originally posted by BBX:
No, that's wrong - the button is in the action menu of an object, where you have the tabs like Main 1, Main 2, and so on.

Okay i get it now, i entered the code you linked me. I changed the "waterfall" to "sound3". the "snd." remains which i'm not sure i should do or not. I run the game and i get an error. i hear the music but the screen is black.
Blind May 2, 2016 @ 9:17am 
99% of the time the error is where the error message says it is. Unironically, this is a novel feautre - most programs have bad error messages.
Püloo Cthulhu May 2, 2016 @ 9:41am 
Originally posted by BBX:
99% of the time the error is where the error message says it is. Unironically, this is a novel feautre - most programs have bad error messages.

if !global.SFX { audio_stop_sound(nearsong); } else { audio_play_sound_at(nearsong, x, y, 0, 100, 300, 1, true, 1); }

near song is my background music and in the code it appears red. Is there anything else in the template i need to change?
Blind May 2, 2016 @ 9:44am 
If you read the context of the page - the variable global.SFX is a controller for if sound is turned on or off and isn't needed in this context.

Obviously you already have the music playing somehow - otherwise you wouldnt' be having a looping problem. Just put an "if" before that that if the music is already playing... stop it.
Püloo Cthulhu May 2, 2016 @ 10:07am 
Originally posted by BBX:
If you read the context of the page - the variable global.SFX is a controller for if sound is turned on or off and isn't needed in this context.

Obviously you already have the music playing somehow - otherwise you wouldnt' be having a looping problem. Just put an "if" before that that if the music is already playing... stop it.

Couldn't get it to work but thanks for trying.
Am I correct you're just making a really basic game with a single song being used as the background music?

If you are and your game already plays the music properly the first time and your room is able to reset properly when you collide into walls then a fairly basic and simple solution would be to just stop the song from playing whenever you run into walls, but before the room is restarted.

So in your collision event with your walls just before the action you've placed to restart the room you could put an "execute code" action like BBX told you about. In that code you could put ...
audio_stop_sound(nearsong);
... or whatever your song is called.


The reason you're getting repeating overlayed songs is because you're always telling them to play, but never telling them to stop. So everytime you restart its creating a new intances of the song and playing it even though there is already one, or more, instances of the song already playing from the last time the room was being run.


Another fairly basic and simple solution would be to check if the song is already being played before playing it again. By using ...
if !audio_is_playing(snd_Waterfall)
... as a check before you play the song again. The "!" at the start of that "audio_is_playing" means essentially to do the opposite. So what its doing is checking if the song is NOT already playing and if so then you would start your song playing.

In your situation though I'd think just stopping the song after the collision, but before restarting the room, would be the quickest and easiest method.
Last edited by BOYCOTT S-T-E-A-M!; May 3, 2016 @ 12:48am
Püloo Cthulhu May 3, 2016 @ 10:53am 
Originally posted by BOYCOTT S-T-E-A-M!:
Am I correct you're just making a really basic game with a single song being used as the background music?

If you are and your game already plays the music properly the first time and your room is able to reset properly when you collide into walls then a fairly basic and simple solution would be to just stop the song from playing whenever you run into walls, but before the room is restarted.

So in your collision event with your walls just before the action you've placed to restart the room you could put an "execute code" action like BBX told you about. In that code you could put ...
audio_stop_sound(nearsong);
... or whatever your song is called.


The reason you're getting repeating overlayed songs is because you're always telling them to play, but never telling them to stop. So everytime you restart its creating a new intances of the song and playing it even though there is already one, or more, instances of the song already playing from the last time the room was being run.


Another fairly basic and simple solution would be to check if the song is already being played before playing it again. By using ...
if !audio_is_playing(snd_Waterfall)
... as a check before you play the song again. The "!" at the start of that "audio_is_playing" means essentially to do the opposite. So what its doing is checking if the song is NOT already playing and if so then you would start your song playing.

In your situation though I'd think just stopping the song after the collision, but before restarting the room, would be the quickest and easiest method.

Okay i got it to work man, thank you so much! Only problem now is that i don't want the song to reset i just want it to continue wihtout overlapping however with all this effort i think i'll just leave it as it is. Thank you so much man i really appreciate the time you took to help me out <3
Glad you got it to stop repeating.

If you want it to not reset the song then instead of stopping the song before reseting the room you'll want to do that second thing I mentioned where you check if the song is playing already and only play it if it isn't already playing.

That should make you only have the song play once and not stop even if you reset the room. Be sure you have the audio set to loop though otherwise it won't restart the song when it reaches the end.
Last edited by BOYCOTT S-T-E-A-M!; May 3, 2016 @ 12:45pm
< >
Showing 1-15 of 15 comments
Per page: 1530 50

Date Posted: May 2, 2016 @ 8:16am
Posts: 15