Can anyone help me with this code?

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

So I wanted to make a double jump counter and this is the code (jump_counter start from 0):

func _on_HUD_up():
 jump_counter += 1
 if jump_counter == 1:
	motion.y = jump_height
 elif jump_counter == 2:
	motion.y = jump_height

The function is trigger on signal from a TouchScreenButton.
I print(jump_counter), it should be 1, 2, 3 but I get 1, 1, 2, which make the character able to triple jump instead.

Plus, the first “1” doesn’t even play the AnimatedSprite.

Am I doing something wrong?

On which occasions/events do you reset jump_counter to 0 ?
Add prints into all 3 if branches (and to the code where you reset jump_counter to 0) to see what happens.

wombatstampede | 2019-11-20 08:55

what’s the default jump_counter value and where do you set it back to default after the jump

zen3001 | 2019-11-20 13:21