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

GML playSFX Script

Hey guys!
I want to create a script that plays a sound once that is then executed after a certain action, for example with landing. Here's my code:
GML:
///@param sound
function playSFX(argument0)
{
    audio_stop_sound(argument0);
    audio_play_sound(argument0, 100, false);
}
However, when I execute this script, the sound keeps on looping.
 
Why don't you check to see if it's playing first...

GML:
function playSFX(argument0) {
    if !audio_is_playing(argument0) {
        audio_play_sound(argument0, 100, false);
    }
}
 

jonjons

Member
set the room speed to 1

GML:
room_speed = 1;
or


GML:
function playSFX(argument0)
{
    audio_stop_sound(argument0);
    if ( ! audio_is_playing(argument0) )
    {
        audio_play_sound(argument0, 10, false);
    }
}

GML:
function playSFX(argument0)
{
    if ( audio_is_playing(argument0) )
    {
        exit;
    }
    else
    {
    audio_play_sound(argument0, 10, false);
    }
}
 

Nidoking

Member
No, I don't. The script is executed in another script used for collision, and it is only written once.
How many times do things in your game collide?

I believe you are incorrect in this statement, but feel free to post your code and back yourself up. As an added bonus, someone might be able to tell you how to fix it in specifics, rather than the general advice we're stuck with now.
 
Top