double Jump working but count not working????

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

hi, help please

i have a double jump working correctly, but i want to print the jumps but due to resetting at the floor the jump count at the floor it doesn’t print the first jump, only 2nd

if Input.is_action_just_pressed("jump"):
	jumps_count -= 1
	if jumps_count != 0:
		motion.y = JUMP_HEIGHT

if is_on_floor():
	jumps_count = 3
   
  print(jumps_count)

printout is 3 on floor, 3 for first jump and 2 for second!

pretty sure it’s to do with the resetting on is_on_floor() but not sure how to solve
any help would be great, driving me nuts

thanks

:bust_in_silhouette: Reply From: jgodfrey

Untested, but I think this should work. That said, you need to initialize your jump counter outside of the whatever function the code below lives in.

if Input.is_action_just_pressed("jump"):
    if jumps_count > 0:
        jumps_count -= 1
        motion.y = JUMP_HEIGHT

if is_on_floor():
    jumps_count = 2

print(jumps_count)