I am following the turoial above on state machines
extends Node
@export
var startingstate: State
var current_state : State
var currentstate: State
func _init(parent : Player) -> void:
for child in get_children():
child.parent = parent
change_state(startingstate)
func change_state(new_state : State) -> void:
if currentstate:
currentstate.exit()
currentstate = new_state
currentstate.enter(
)
func process_input(event: InputEvent) -> void:
var new_state = current_state.process_input(event)
if new_state:
change_state(new_state)
func process_frame(delta: float) -> void:
var new_state = current_state.process_frame(delta)
if new_state:
change_state(new_state)
sorry but I posted this to reddit and they deleted the @onready because they thought I was mentioning another user and I replaced it with @export here my apologies but It was originally meant as @onready
_init() is a built-in callback, that may break the node when you change it like that.
Note: If _init() is defined with required parameters, the Object with script may only be created directly. If any other means (such as PackedScene.instantiate() or Node.duplicate()) are used, the script’s initialization will fail.