how do i get jums to replenish

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

my movement code is not replenishing jumps when it touches a tilemap how should i fix this? code is below:

extends KinematicBody2D

const GRAVITY = 10 # in pixels
const JUMP = 250 # start speed px/s
const SPEED = 200 # px/s

var velocity = Vector2.ZERO # (0,0)
var jumps_available := 2	

func _ready():
	pass

func _on_Timer_timeout():
	print(str($Timer.wait_time) + " second(s) finished")

func _physics_process(delta):

	# if no keyboard input for left/right then x speed is 0
	velocity.x = 0 
	if(Input.is_action_pressed("right")):
		velocity.x = SPEED
	elif(Input.is_action_pressed("left")):
		velocity.x = -SPEED

	velocity.y += GRAVITY

# _physics_process
	if Input.is_action_just_pressed("jump") and jumps_available > 0:
		velocity.y -= 250
		jumps_available -= 1
		# _physics_process
		if is_on_floor():
			jumps_available = 2

	velocity = move_and_slide(velocity)

how can i fix this?

:bust_in_silhouette: Reply From: Bernard Cloutier
      if is_on_floor():
            jumps_available = 2

That part will never be executed, since it’s within this other block:

if Input.is_action_just_pressed("jump") and jumps_available > 0:

If jumps are 0, then it’s not going to enter this block and refill them, since you are requiring the jumps to be above 0.

I think what you meant to do is this:

    if Input.is_action_just_pressed("jump") and jumps_available > 0:
        velocity.y -= 250
        jumps_available -= 1

    if is_on_floor():
        jumps_available = 2

(Notice the indentation change)