SOLVED How can I only jump once if I fall off a cliff? double jump problem

Hello, I have this problem where my player can jump twice after he fell off a cliff. I've programmed my character so he can double jump using "jumps" and "jumpsmax" has statements as the numbers of jumps allowed and the numbers of jumps remaining respectively.
I allowed my player so he can only jump two times before the numbers of "jumpsmax" equals 0, implying that the number of jumps remaining equals 2 while on the ground. I need to find a way to allow the player to only jump once once he is in the air after he fell off a cliff, implying that I need the numbers of jumps remaining ("jumpsmax") to be 1 once the player fell off a cliff so he can only jumps once once in the air.

Here is the chunk of code about the "Jump Status".

Code:
#region Jump Status



if (onground == true)                                                              //onground jump

{

    jumps = jumpsmax;

}

if (key_jump && jumps > 0)                                                    //on air jump

{

    jumps -= 1;

    if (key_jump) vsp = -jumpsp;                                               //jump velocity

    if (onground) audio_play_sound(snJump1,1,false);            //set audio sound when on ground jump

    if (key_jump && !onground)                                               //set audio sound when not on ground jump

    {

        audio_play_sound(snJump2,1,false);

    }

}



if (vsp < 0 && !key_jump_held) vsp = max(vsp,-2);                //change jump velocity while not helding key jump



#endregion
onground variable meaning place_meeting(the floor) (on Create event "onground = false", on Step event "onground = place_meeting(x,y+1,oWall);" oWall is the object I use to the floor and the wall, because it's an invisible block in-game.
jumps variable meaning numbers of jumps remaining (on Create event "jumps = jumpsmax;")
jumpsmax variable meaning numbers of jumps allowed (on Create event "jumpsmax = 2;")

Also, when I mean when my player fell off a cliff, I mean when you as the player just simply run and fell off because there's no more floor below him.
I think there's no more info necessary to address my problem. If anyone knows the solution about this problem, please let me know, I would be really grateful.
 
Last edited:
When you know the player is no longer on the ground, just can just force jumps to be 1 or lower: jumps = min(jumps,1);. That way, if the player has 2 jumps and they jump off the ground, then there's no problem, as they will use one of their jumps and then jumps will be set to 1, if they jump again, jump will end up being 0 and the code will pick the minimum of 1 or 0 (of which, obviously, 0 is lower). If they fall off a cliff, they'll have 2 jumps, the code will run and their jumps will be set to 1. The code I provided above can be used continuously while in the air (that's why I'm using min() instead of simply setting jumps to 1), however, for better code structure, it's probably best to set it only once as the transition is made from being on the ground to being off the ground.
 
It actually works!! thanks man :)
I changed the code, so instead of:
GML:
if (onground == true)

{
    jumps = jumpsmax;
}
it'll be like:
Code:
if (onground == true)
{
    jumps = jumpsmax;
}
else jumps = min(jumps,1);
Again, thanks for the replay, i had this problem for days.
 
Top