• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

Stop sound option after two jumps

I have a double jump in place and currently, when you press the gamepad button, the jump sound plays along with the action. However, if you're still in the air and continue to press "jump", it keeps triggering the jump sound. I'm still a beginner, and I don't always understand how to write out the logic. Any suggestions?

if (gp_jump) {
    audio_play_sound(a_jump, 1, false);
    sprite_index = s_player_jump;

if (on_ground) {
    jumps = 0; // This will reset your jumps when you land and you will be able to double jump again

if (gp_jump and jumps <= jumps_max) { // You can jump until your "jumps" variable has reached your "jumps_max" variable
    if not on_ground { sprite_index = s_player_high_jump; }
    audio_play_sound(a_jump, 1, false);
    jumps += 2; //Adds to your jump
    y_speed = -jump_power;