GameMaker Sound playing every step. (need to stop that)

Okay so simple enough I want a hover sound to play when the characters HSP (horizontal speed) is > 0. So if this is the case and its HSP > 0 then I set the hovering var to be true. Otherwise its false. Once hovering is true I do the following (hovering code included).

PLAYER - CREATE

GML:
hovering = false;
PLAYER - STEP
GML:
if (!place_meeting(x, y + 1, allCollide))
{
    sprite_index = sHero_jump
    image_speed = 0;
    if (sign(vsp) > 0) image_index = 1; else image_index = 0;
}
else
{
    canjump = 10;
    image_speed = 1;
    if (hsp == 0)
    {
        sprite_index = sHero_idle;
        hovering = false;
    }
    else
    {
        sprite_index = sHero_run;
        hovering = true;
    }                     
    if (walksp == 5)
    {
        sprite_index = sHero_run;   
        hovering = true;
    }
}
GML:
if (hovering) {
    sc_playFX(sn_heroHover, 10, false);
} else {
    audio_stop_sound(sn_heroHover);
}
SCRIPT


GML:
var _playable = true;

if (_playable) {
    audio_play_sound(argument0, argument1, argument2);
    _playable = false;
} else {
    _playable = true;   
}
I set the hovering audio to not loop so I can test it. It sounds like its looping so that tells me its playing every step, which I dont want. I just want it to turn on ONCE play looped and the turn off when the HSP = 0.
 

FrostyCat

Redemption Seeker
Your sound-playing script does basically nothing new because _playable goes back to true every time it's called. This is a case of misplaced faith and failure to trace.

What you should do is using pattern 1 from my article on anti-repetition flags.

Create:
GML:
hovering = false;
hovering_playable = true;
hovering_sound_instance = -1;
Step hover check:
GML:
if (hovering) {
    if (hovering_playable) {
        hovering_sound_instance = audio_play_sound(sn_heroHover, 10, true);
        hovering_playable = false;
    }
} else {
    if (hovering_sound_instance != -1) {
        audio_stop_sound(hovering_sound_instance);
        hovering_sound_instance = -1;
    }
    hovering_playable = true;
}
Pay attention to how my flag doesn't go back to true willy-nilly the way your original does.
 
Top