Sound in the room repeats loop

sensodyne

Member
Good morning,


I have a little problem ... I don't know why my room (game over) music is playing in a loop ... I've already changed the value from 1 to 0 but it doesn't help ... What am I doing wrong?
I would like this music to be played only once ..


obj_sound_system

step

GML:
m=music_game_over
if(room=room_game_over) {
    if(!audio_is_playing(m)) {
        audio_play_sound(m,1,0) //here I changed from 1 to 0
    }   
} else {
    audio_stop_sound(m)
}
 

TsukaYuriko

šŸŒ 
Forum Staff
Moderator
Your code states "If we're in the game over room and the game over music is not playing, play the game over music".

After it finishes playing once, it is no longer playing. If it's not playing, it will be played again. And again. And again.
 

sensodyne

Member
Your code states "If we're in the game over room and the game over music is not playing, play the game over music".

After it finishes playing once, it is no longer playing. If it's not playing, it will be played again. And again. And again.




Oh yes it plays all the time ... and I can't stop it ... so what would I have to do to stop the music after playing it once?
 

TheouAegis

Member
Remove that conditional that checks if it's not playing.

Wherever your code is that has room_goto(room_game_over), stop the audio there. Or in the Room Settings for room_game_over, stop the audio.
 

Nidoking

Member
Remove that conditional that checks if it's not playing.

Wherever your code is that has room_goto(room_game_over), stop the audio there. Or in the Room Settings for room_game_over, stop the audio.
That reverses the logic, though. The code presented plays the sounds when it IS in the room_game_over.

Have you tried moving this to the Room Start Event of its object? It clearly seems to be a persistent instance, so it should exist before the room starts, and exactly the same code would make the music play when you enter the room and make it stop when you leave, but as long as you stay in the room, the music won't re-trigger.
 

TheouAegis

Member
I meant stop all sounds in the room_start. Then he doesn't need to check if music_game_over isn't playing, because nothing would be playing. But you're right, I forgot to address moving the actual playing of the audio to the Room Settings as well (or Room Start, if you prefer).
 
Top