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

Legacy GM GameMaker: Studio Audio Bug/Issues

E

Eilfennol

Guest
I'm not sure why, but audio code isn't executing right. Essentially, I am using audio_is_playing(sound), but it'll actually start the block even though the sound is still playing. Then I want to stop a sound from playing when it leaves the room and I use the audio_stop_sound(sound) function however it doesn't stop the sound at all. I don't know if it is me or GM.
 

johnwo

Member
Are you using the new audio engine? (Global Game Settings->Use New Audio Engine)
Are you playing the sound using audio_play_sound?

If your answer to both is yes, then please post some code.

Cheers!
 
E

Eilfennol

Guest
Code:
///drawing warning symbols
if(global.freeze == false)
{
    if(start_warning == true and (audio_is_playing(snd_megawarning) or audio_is_playing(snd_gigawarning)))//show signs during sound
    {
        draw_sprite_ext(spr_warning,image_index,384,48,1,1,0,c_white,.7);
        draw_sprite_ext(spr_warningsign,image_index,160,32,1,1,0,c_white,.7);
    }
    else if(start_warning == true and (!audio_is_playing(snd_megawarning) and !audio_is_playing(snd_gigawarning)))//stop showing signs shoot missile
    {
        if(megalaunch == true)//launch megabomb
        {
            instance_create(x-15,irandom_range(0,750),obj_megabomb);
            megalaunch = false;
        }
        else if(gigalaunch == true)//launch gigabomb
        {
            instance_create(x-15,irandom_range(0,750),obj_gigabomb);
            gigalaunch = false;
            audio_resume_sound(snd_bg1);
        }
        start_warning = false;
    }
}
So this code is in the draw even of an object. This is where I'm having the issue with the audio_is_playing. So one of those sounds will play via an alarm function in any case a sound is being played. While the sound is playing draw those sprites. Eventually the sound will stop and that is when it should continue, it does that but it does it before one of those sounds stop playing. The next problem is after it creates obj_gigabomb.

In the creation event of obj_gigabomb I play the audio_function to play the "snd_missile" sound. This works fine. Here is the code when it is supposed to stop playing the snd_missile which is inside a step event.

Code:
///destroy bomb if they leave the room
if(self.x < -32)
{
    if(global.gauntlet = true && !object_exists(obj_deathdisplay))
    {
        score+=200*ninja.scoremultiple;
        global.coins+=300;
    }
    audio_stop_sound(snd_missile);
    instance_destroy();
}
So basically I know the code gets executed because I see the bomb disappear/get destroyed, it's a big sprite with it's origin at 0,0, I did that so I can make sure it is being executed. And there is the problem. It doesn't stop the sound at all. Even though it goes through the line of code and destroys the object. Not only that I even tried having a Destroy event for the object and use DnD to stop the sound and it doesn't work. But I also know the code is executed because when obj_gigabomb is created i create another object to just shift the view (creates a shake effect) and that object as well gets destroyed and view stops moving from the Destroy event of obj_gigabomb.
If you need anymore clarification just ask.
 
E

Eilfennol

Guest
Just an update, tried numerous various changes to code and creating a new sound to no success. Something must be wrong in the backend and I have no idea what to do.
 

obscene

Member
Sorry I missed your earlier reply.

Ok, it's still very hard to follow what's going on and what could be happening unless you dumped all relevant code as we can't know what variables are set to what values when and when sounds are started playing etc. You have a ton of stuff going on that you don't show.

Something you should do to help yourself find this is use show_debug_mesage() and then watch your compiler window while you run.

Examples...
  • show_debug_message("Line 432 returned true")
  • show_debug_message("Global.gauntlet: " + string(global.gauntlet))

Also a few coding pointers:
  • Yoyo recommends not putting important code in the draw event as it's already a heavy event plus there are methods you can use to optimize your game later that might actually skip draw events and having functional code in here will break your game.
  • self.x should just be x. Self is rather useless.
  • you can say things like "if gigalaunch" or "if !gigalaunch" instead of "if (gigalaunch == true)" to make your code a little more readable.
  • IMPORTANT: About "audio_stop_sound(snd_missile);" Realize if you have multiple missles on screen and multiple sounds playing this would stop them ALL. (This might be related ot your bug). When you play a sound, assign it an index like "snd = audio_play_sound(snd_missile,etc.)" Then later you would write "audio_stop_sound(snd)"
Sorry I'm not more helpful.
 
E

Eilfennol

Guest
I showed all the relevant code pertaining to the sound issues I was having. The weird thing is all this code actually worked. Then when I came back to it and altered the 'snd_missile' to a slightly different sound is when I started getting this weird behavior.
Yoyo recommends not putting important code in the draw event as it's already a heavy event plus there are methods you can use to optimize your game later that might actually skip draw events and having functional code in here will break your game.
I understand this but all this code is being executed right/going into the right code blocks, but not at the right time. But I will try and take all the stuff out except the code that uses the draw functions and see what happens.

IMPORTANT: About "audio_stop_sound(snd_missile);" Realize if you have multiple missles on screen and multiple sounds playing this would stop them ALL. (This might be related ot your bug). When you play a sound, assign it an index like "snd = audio_play_sound(snd_missile,etc.)" Then later you would write "audio_stop_sound(snd)"
This I already tried when I looked at the GameMaker manual for insight to no avail. Regardless, not that you could tell from my code but only 1 gigamissile will be created and 1 'snd_missle' be playing at a time.

I'm still confused how the 'snd_missile' doesn't stop the sound when clearly the block of code is executed. I'll try to use those debug messages functions but I've never used them before. I'll look at the manual on how to use them and see if I can gain any more insight by using them.
 
E

Eilfennol

Guest
  • Ok I made the changes. First I changed the draw_event to only have one bool if statement where if true it'll use two draw_functions. The rest of the stuff I put into the step event. This didn't solve the issue where snd_missile was playing before the snd_megawarning or snd_gigawarning were finished.
  • On a hunch I decided to approach the problem not by my code but something wrong with the sound. Here is what I found.
  • In obj_gigabomb step event the code which is right here for convenience:

Code:
///destroy bomb if they leave the room
if(self.x < -32)
{
    if(global.gauntlet = true && !object_exists(obj_deathdisplay))
    {
        score+=200*ninja.scoremultiple;
        global.coins+=300;
    }
    audio_stop_sound(snd_missile);
    instance_destroy();
}
  • I used the show_debug_message() function and if statements after audio_stop_sound(snd_missile) to see if according to GameMaker the sound was still playing or not.
  • The result was that in the compiler I got the message that said "SOUND STILL PLAYING". Below is the updated code from just above.

Code:
///destroy bomb if they leave the room
if(x < -32)
{
    if(global.gauntlet = true && !object_exists(obj_deathdisplay))
    {
        score+=200*ninja.scoremultiple;
        global.coins+=300;
    }
    audio_stop_sound(snd_missile);
    if audio_is_playing(snd_missile){show_debug_message("SOUND STILL PLAYING!");}
    else {show_debug_message("SOUND NOT PLAYING!");}
    instance_destroy();
}
  • This made me decide that something has to be wrong with the sound snd_missile, so next I did two things.
  • On creation of obj_gigabomb instead of playing snd_missile which i commented out I played another sound, called snd_earndedachievement, to see what would happen. (This is where it gets good lol)
  • So it turns out that snd_earnedachievement properly plays when snd_megawarning or snd_gigawarning stop playing but get this; the snd_missile even though I commented it from playing was still playing as though I didn't comment the line out even though I did.
  • Obviously my next step was to check if I had something else using snd_missile so I used GM's search in script to find any stray snd_missile variables anywhere. I found nothing
  • So I straight up deleted snd_missile from GM and another sound that was like snd_missle only it fades immediately. After doing this and playing the game with these changes the friggin sound is still playing!
So basically I have no clue how to fix this lol but I found the problem. Somehow GM is playing a sound I'm not telling it to play and when I tell it to delete it, it clearly can't find it so the sound continues to play. Anyone know how to fix this?

PS: If you need anything explained a bit more or need more code/info just reply. :)
 
S

seanm

Guest
Try clearing your cache.
Make sure your project is not in something like Google drive, the auto sync can seriously mess with project files.
And yeah, then delete snd_missile and re make it.
 
E

Eilfennol

Guest
Try clearing your cache.
Make sure your project is not in something like Google drive, the auto sync can seriously mess with project files.
And yeah, then delete snd_missile and re make it.
Ok, so I made sure I don't have it in a cloud service, and deleted snd_missile and remade it to no avail. At this point I think I'm just going to make a new project and copy everything over. I'm sure that'll get past whatever problem GM is having with this project I'm using.
 
S

seanm

Guest
Try changing the export module.

And try closing the project and reopening it.
 
E

Eilfennol

Guest
hi, did you manage to solve that problem?
Sadly no, I had a backup in my onedrive cloud service and I didn't run into the bug there. But anytime I try to bring it out from the cloud to being on my PC I run into the bug. It's super annoying but I got around it by just using my backup from onedrive.
 
Sadly no, I had a backup in my onedrive cloud service and I didn't run into the bug there. But anytime I try to bring it out from the cloud to being on my PC I run into the bug. It's super annoying but I got around it by just using my backup from onedrive.
well, my solution was to divide on different steps
  • audio_stop_sound ()
  • checking if (audio_is_playing()) with next game logic
In one step both of them didn't work correct altogether.
 
Top