How do I make it so my air-dash can only be used once in air and resets after jumping again

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

const DASH_SPEED = 2000
const MAX_SPEED = 128
const ACCEL = 512
const FRICTION = 0.30
const GRAVITY = 600
const JUMP_FORCE = 200
const AIR_RESISTANCE = 0.02

var vel = Vector2.ZERO

onready var sprite = $Sprite
onready var animationPlayer = $AnimationPlayer

func run(directionstrength, delta):"Run")
	vel.x += directionstrength * ACCEL * delta
	vel.x = clamp(vel.x, -MAX_SPEED, MAX_SPEED)
	sprite.flip_h = directionstrength < 0 
func jump():
	vel.y = -JUMP_FORCE
func applyfriction():
	vel.x = lerp(vel.x, 0 , FRICTION) 

func jumpRelease():
	vel.y = -JUMP_FORCE/2

func dash(directionstrength):
	if directionstrength > 0:
		vel.x += DASH_SPEED
	elif directionstrength < 0:
		vel.x += -DASH_SPEED
		vel.x = 0

func _physics_process(delta):
	vel.y += GRAVITY * delta
	var x_direction = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
	if x_direction != 0:
		run(x_direction, delta)

	if is_on_floor(): 
		if x_direction == 0:
		if Input.is_action_just_pressed("jump"):
		if Input.is_action_just_released("jump") and vel.y < -JUMP_FORCE/2:
		if x_direction == 0:
			vel.x = lerp(vel.x, 0 , AIR_RESISTANCE) 
		if Input.is_action_just_pressed("dash"):
	vel = move_and_slide(vel, Vector2.UP)

How do I make it so that my dash only works one time and resets when you jump again. I cant wrap my head around it. Thanks for the help and sorry for the bad code.

:bust_in_silhouette: Reply From: exuin

Have a variable, like can_dash and set it to false once the player uses the one air-dash. Only let the player dash if its value is true. Once the player jumps again, set its value to true so the player can dash again.

:bust_in_silhouette: Reply From: GameVisitor

Better to use a Finite State Machine for this purpose.