[SOLVED]music transaction

RODO

Member
hello guys I come to ask for a desperate help for you, this problem is being one of the worst I have ever faced (the others were very bad too but with your help they were not so horrible to fix).

Come on, I'm trying to make an audio system that when it changes rooms it plays a different song, so far I had this idea but the problem is to implement it. I can't get him to work, for example: I can get him to stop playing but he doesn't play anymore or he asks him to play only once and he stays on the same song (there are several other problems but these are some of them)

I'll put the code here for better understanding:
GML:
//create event

sound = 0;
music = 0;
toque = true;
//step event

if(instance_exists(obj_transicao)) // transition obj is the room translation obj, it creates that black screen effect
{
    audio_sound_gain(music,1,0)
    audio_sound_gain(music,0,1000)
    if(audio_sound_get_gain(music) < 0)
    {
        audio_stop_sound(music);
    }
    
}

//room start

audio_sound_gain(music,0,0)
audio_sound_gain(music,1,1000)
toque = true
well, can anyone measure any tips on how to make this system work? this code was one of the many ways that I tried to execute, I tried several codes but nothing gave the result I wanted, and what’s worse is that I tried to do it in a way that it destroyed itself and played again but my other room restarts then there are several songs playing.

NOTE: I do not know if this is useful but the obj that is loading the songs is another, it is not giving a problem and the songs are being loaded normally.

I am grateful for any help, in case it is difficult to understand I will try to explain it in another way.
 

curato

Member
I would think you would want to adjust the music only one time the repeating of it will make your if statement never be true. Also the if statement. You are setting the value to zero so you may want to at least check the equal to case that will likely cause you some issues as well.
 

kburkhart84

Firehammer Games
My upcoming audio system at this stage already handles fading in/out tracks, cross fading, etc... so I can confirm it is 100% doable.

I can't be sure what your issue is really with only the code you are showing there. I see you stopping the music in the step event once it fades out...but is that the music from the old room or the new room? If you are trying to cross-fade the tracks, you need multiple variables to store which is the old and which is the new.

I bet if you sprinkle some debug logs all over the place...and possibly even set a breakpoint and step through the code, you will likely figure out the issue. I'm guessing it is a logical problem, not a code problem. That means that you may not have thought out what you are doing and so your code is doing what you tell it even though that isn't what you really want.
 

kburkhart84

Firehammer Games
Right on! Rock and Roll, man!
:eek: 😅

LOL, I somehow didn't notice they are trying to set gain 1000x over what is the supposed max. I should have caught that as I had to verify the proper range when I wrote part of my system. I'm not sure if that is what the issue is or not but it is CERTAINLY an issue either way!
 
:eek: 😅

LOL, I somehow didn't notice they are trying to set gain 1000x over what is the supposed max. I should have caught that as I had to verify the proper range when I wrote part of my system. I'm not sure if that is what the issue is or not but it is CERTAINLY an issue either way!
My guess is it would clip like hell, but not throw an error (I'd be surprised!).
This part, tho, makes it so that the music would never stop, even at gain at 0. Maybe it's just a matter of using the <= comparaison...
Kind of all depends how obj_transition is spawned/destroyed.
GML:
    audio_sound_gain(music,1,0)
    audio_sound_gain(music,0,1000)
    if(audio_sound_get_gain(music) < 0)
    {
        audio_stop_sound(music);
    }
 
D

Deleted member 13992

Guest
They're not setting the gain to 1000x. That's the time to change the gain (to 1) in milliseconds.
 
They're not setting the gain to 1000x. That's the time to change the gain (to 1) in milliseconds.
Honestly, I know the parameters are gain, then delay (no hard feelings, but you just didnt get the joke, bro, lol), but the point is that the audio stop part will never ever run, no matter how he sets his volume.
 

kburkhart84

Firehammer Games
They're not setting the gain to 1000x. That's the time to change the gain (to 1) in milliseconds.
C'mon, let us have some fun!

Honestly, I know the parameters are gain, then delay (no hard feelings, but you just didnt get the joke, bro, lol), but the point is that the audio stop part will never ever run, no matter how he sets his volume.
This point I did actually miss...here is to hoping the code/logic is sound and they only need to fix the comparison.
 
This point I did actually miss...here is to hoping the code/logic is sound and they only need to fix the comparison.
I don't really know. If it was me, I'd throw all that step event in the garbage and only work within the room start event, for a simple case of playing the correct theme song for the correct level. The fades could very well be within the audio file itself and no one would ever notice. This seems like the OP problem was quite simple: I'm trying to make an audio system that when it changes rooms it plays a different song . A simple persistent game manager object would handle that like a champ, no problem!
GML:
//Room start event
if(audio_is_playing(some_bg_music)){
    //stop music
}

//play the new level theme song
 

kburkhart84

Firehammer Games
I don't really know. If it was me, I'd throw all that step event in the garbage and only work within the room start event, for a simple case of playing the correct theme song for the correct level. The fades could very well be within the audio file itself and no one would ever notice. This seems like the OP problem was quite simple: I'm trying to make an audio system that when it changes rooms it plays a different song . A simple persistent game manager object would handle that like a champ, no problem!
GML:
//Room start event
if(audio_is_playing(some_bg_music)){
    //stop music
}

//play the new level theme song
That's the idea I'm doing in my audio system. Music is one category of audio. It has separate functions to handle it. You only have to call a function to switch to a different music track, and you can call it wherever you want(room_start, controller create event for a room, whatever). The object always knows what music it is playing and tracks its reference so it can fade/stop it. As you say, a simple object with some code is the trick. In my case I also store where the track was so you can choose to continue from where it previously was when you come back to it. Once you use an object and have things going, it is easy enough add more features as needed.
 
In my case I also store where the track was so you can choose to continue from where it previously was when you come back to it.
That is really, really neat. Although a semi-edge case, I can see this being very useful in something like a rhythm game, so you can pause/resume the game without ******* it all up!
Dialogs systems, too..
 

kburkhart84

Firehammer Games
That is really, really neat. Although a semi-edge case, I can see this being very useful in something like a rhythm game, so you can pause/resume the game without ******* it all up!
Dialogs systems, too..
It's actually useful in any games that have multiple scenes, like RPGs that transition to fight scenes, or if you have different music for the world map and the towns, etc... FF7 was my first exposure to this. If you have a nice world map song of several minutes, many players won't hear the good stuff later in the track if it keeps restarting every time you come out of a battle.
 
FF7 was my first exposure to this. If you have a nice world map song of several minutes, many players won't hear the good stuff later in the track if it keeps restarting every time you come out of a battle.
I actually never noticed that, and played the heck out of that game!
Definitely makes sense when you think about it, tho!
 

RODO

Member
wow, I read all of your comments and it was really helpful, in fact I think it was my mistake and not the code, I was already very stressed and frustrated by not getting it and I started not having a good idea. I will use your tips and redo the objs and codes, I think it is easier to correct the case, thank you all so much, that was of great help.
I am not going to lie but some things left me confused there, in relation to music since I am new to the game maker, so there is still a lot for me to learn, but this I can learn over time and correct myself. And again, thank you
 
Top