Who do I make it so if the player not on the ground I takes away 1 jump.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Yetely

So I have a variable call “jump_count” so what I tried is:

if is_on_floor():
	jump_count = 3
elif not is_on_floor():
	jump_count -= 1

This just takes 1 jump each frame , and doesn’t just take one jump if I’m not on the ground.

:bust_in_silhouette: Reply From: ejricketts

It seems as though you are checking whether or not you are on the ground each frame, and if you are not then decrease by 1 each step.

What would be better is when you jump to reduce the jump_count variable within your jump function, and then if you have enough “jumps left” then you can jump.

# called when on floor and jump button pressed
func jump():
    # reduces count by 1
    jump_count -= 1
    # if you have enough counts left then jump
        if jump_count != 0:
           motion.y = -JUMP_FORCE