State machine not working, using youtube tutorial

Godot 4.3

I’m following this tutorial: https://www.youtube.com/watch?v=it0lsREGdmc&t=3148s and am around 53 minutes in. I changed the direction in the idle state to player.player_direction like instructed, but now my character will not enter the walk state. II press the input keys and nothing happens. here is my code for both the idle and walk states:

idle:

‘’'gdscript
extends NodeState

@export var player: Player
@export var animated_sprite_2d: AnimatedSprite2D

func _on_process(_delta : float) → void:
if player.player_direction == Vector2.UP:
animated_sprite_2d.play(“up_idle”)
elif player.player_direction == Vector2.DOWN:
animated_sprite_2d.play(“down_idle”)
elif player.player_direction == Vector2.LEFT:
animated_sprite_2d.play(“left_idle”)
elif player.player_direction == Vector2.RIGHT:
animated_sprite_2d.play(“right_idle”)
else:
animated_sprite_2d.play(“down_idle”)

func _on_physics_process(_delta : float) → void:
pass

func _on_next_transitions() → void:
GameInputEvents.is_movement_input()

if GameInputEvents.is_movement_input():
	transition.emit("walk")

func _on_enter() → void:
pass

func _on_exit() → void:
animated_sprite_2d.stop()
‘’’

walk:

‘’'gdscript
extends NodeState

@export var player: Player
@export var animated_sprite_2d: AnimatedSprite2D
@export var speed = 50

func _on_process(_delta : float) → void:
pass

func _on_physics_process(_delta : float) → void:
var direction: Vector2 = GameInputEvents.movement_input()

if direction == Vector2.UP:
	animated_sprite_2d.play("up_walk")
elif direction == Vector2.DOWN:
	animated_sprite_2d.play("down_walk")
elif direction == Vector2.LEFT:
	animated_sprite_2d.play("left_walk")
elif direction == Vector2.RIGHT:
	animated_sprite_2d.play("right_walk")
	
if direction != Vector2.ZERO:
	player.player_direction = direction

player.velocity = direction * speed
player.move_and_slide()

func _on_next_transitions() → void:
GameInputEvents.is_movement_input()

if !GameInputEvents.is_movement_input():
	transition.emit("idle")

func _on_enter() → void:
pass

func _on_exit() → void:
animated_sprite_2d.stop()
‘’‘’

Nice!

In future, if you’re posting code, it’s easier to read if you do this:

```gdscript
[your code here]
```

thankyou! I was wondering how people made it look like that

I temporarily fixed this by switching the “if GameInputEvents.is_movement_input():” to if !GameInputEvents.is_movement_input"

but now the walk sprite will not switch back to idle when I stop moving. I’ve tried several attempts to fix this but can’t seem to figure it out.

I’m trying to do that and it isn’t working? it’s only showing the special format on code blocks that start with “if”

You need to do something like:

```gdscript
extends NodeState

@export var player: Player
@export var animated_sprite_2d: AnimatedSprite2D

[…and so on…]
```