• 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!

problem with level music.

pixeltroid

Member
So I assign level music tracks for the rooms in my game in the room editors creation code.

My game requires the player to return to some rooms/levels so I have tried to set up a system that plays the proper track and also:

a) check if the level OST is already playing and prevent it from playing the same OST over itself.
b) check if another tract from another level is playing and fade it out.

Here's what the code looks like

Code:
//fades out track from previous room
if global.BGM!=ost_3
{
audio_sound_gain(global.BGM, 0, 3000);
}

//prevents the current track from playing
else if audio_is_playing(ost_3){
exit;
}

//plays main level music
audio_sound_gain(global.BGM, 0, 3000);
global.BGM = audio_play_sound(ost_3, 8, true);
So far, this only fades out the previous rooms track....BUT if I have, say, "ost_3" playing and I enter a room with the same track assigned to it, the track fades out in 3 seconds and the new instance of the same track starts playing from the start. I'm confused as to why its happening even

What am I doing wrong exactly?

How can I fix the code to make it so that the current track doesnt start playing over itself?


Any help would be appreciated!
 
Last edited:
N

NoFontNL

Guest
You could do this.
Code:
var newMusic=ost_3_or_whatever_new_music_to_play // New music
if(asset_get_index(asset_get_name(global.BGM)) != newMusic) { // If the music is NOT the same,
        audio_sound_gain(global.BGM,0,3000); // then fade out ...
        global.BGM=audio_play_sound(newMusic,8,true); // ... and play the new music.
        audio_sound_gain(global.BGM,1,1000) // Bring back the volume I think.
}
I haven't tested this code myself though.
 

pixeltroid

Member
You could do this.
Code:
var newMusic=ost_3_or_whatever_new_music_to_play // New music
if(asset_get_index(asset_get_name(global.BGM)) != newMusic) { // If the music is NOT the same,
        audio_sound_gain(global.BGM,0,3000); // then fade out ...
        global.BGM=audio_play_sound(newMusic,8,true); // ... and play the new music.
        audio_sound_gain(global.BGM,1,1000) // Bring back the volume I think.
}
I haven't tested this code myself though.
Hi. thanks for your post. But Im using 1.4 and its not recognizing asset_get_name as a function :/
 

pixeltroid

Member
You could do this.
Code:
var newMusic=ost_3_or_whatever_new_music_to_play // New music
if(asset_get_index(asset_get_name(global.BGM)) != newMusic) { // If the music is NOT the same,
        audio_sound_gain(global.BGM,0,3000); // then fade out ...
        global.BGM=audio_play_sound(newMusic,8,true); // ... and play the new music.
        audio_sound_gain(global.BGM,1,1000) // Bring back the volume I think.
}
I haven't tested this code myself though.
Hey! I changed asset_get_name to audio_get_game and your code seems to be working perfectly!
Thanks a ton, man!!
 
Top