if else statements not working

Godot Version

4.5.1

Question

i dont know what the problem is with my code but for some reason ive been trying to run animations for walking but whenever i add else statements all the if statements dont work anymore here is my code

if Input.is_action_pressed("ui_right"):
	animation.play("walking_right")
else:
	animation.stop()


if Input.is_action_pressed("ui_left"):
	animation.play("walking left")
else:
	animation.stop()

Because you stop if either left or right is not pressed, you should use elif for the second check instead

if Input.is_action_pressed("ui_right"):
	animation.play("walking_right")
elif Input.is_action_pressed("ui_left"):
	animation.play("walking left")
else:
	animation.stop()

2 Likes

thank you that worked

1 Like