I keep getting this error message when I try to run my game

Godot Version

v 4.3

Ok so I am making a 2d platformer fighting game and currently am trying to set up a state machine but whenever I run my code it keeps telling me “Invalid access to property or key ‘id’ on a base object of type ‘CharacterBody2D (FOX.gd)’.”

the: @onready var id = get_parent().id
is where all my problems are coming from
this is my code:

extends StateMachine
@onready var id = get_parent().id

func _ready():
add_state(‘STAND’)
add_state(‘JUMP_SQUAT’)
add_state(‘SHORT_HOP’)
add_state(‘FULL_HOP’)
add_state(‘DASH’)
add_state(‘MOONWALK’)
add_state(‘WALK’)
add_state(‘CROUCH’)
call_deferred(“set_state”, states.STAND)

func state_logic(delta):
parent.updateframes(delta)
parent._physics_process(delta)

func get_transition(delta):
parent.move_and_slide_with_snap(parent.velocity2,Vector2.ZERO,Vector2.UP)
parent.states.text = str(state)
match state:
states.STAND:
if Input.get_action_strength(“right_%s” % id) == 1:
parent.velocity.x = parent.RUNSPEED
parent.frame()
parent.turn(false)
return states.DASH
if Input.get_action_strength(“left_%s” % id) == 1:
parent.velocity.x = -parent.RUNSPEED
parent.frame()
parent.turn(true)
return states.DASH
if parent.velocity.x > 0 and state == states.STAND:
parent.velocity.x += -parent.TRACTION
1
parent.velocity.x = clamp(parent.velocity.x,0,parent.velocity.x)
elif parent.velocity.x < 0 and state == states.STAND:
parent.velocity.x += parent.TRACTION*1
parent.velocity.x = clamp(parent.velocity.x,parent.velocity.x,0)
states.JUMP_SQUAT:
pass
states.SHORT_HOP:
pass
states.FULL_HOP:
pass
states.DASH:
if Input.is_action_pressed(“left_%s” % id):
if parent.velocity.x > 0:
parent.frame()
parent.velocity.x = -parent.DASHSPEED
elif Input.is_action_pressed(“right_%s” % id):
if parent.velocity.x < 0:
parent.frame()
parent.velocity.x =parent.DASHSPEED
else:
if parent.frame >= parent.dash_duration-1:
return states.STAND

	states.MOONWALK:
		pass
	states.WALK:
		pass
	states.CROUCH:
		pass

func enter_state(new_state, old_state):
pass

func exit_state(old_state, new_state):
pass

func state_includes(state_array):
for each_state in state_array:
if state == each_state:
return true
return false

Have you tried passing that variable from the parent?

var id = something

func _ready()
$State.id = id

The variable on parent is it onready var or is it a regular var?

The problem isn’t with your statemachine script but with the relationship between it and the parent. This is saying that var id on parent isn’t valid.

The parent node has a script with this id variable?

Thanks for trying to help me out, this is the parent code and I can’t seem to figure out why it still doesn’t work

extends Node
class_name StateMachine

var state = null : set = set_state
var previous_state = null
var states = {}

@onready var parent = get_parent()

func _physics_process(delta):
if state !=null:
state_logic(delta)
var transition = get_transition(delta)
if transition != null:
set_state(transition)

func state_logic(delta):
pass

func get_transition(delta):
return null

func enter_state(new_state, old_state):
pass

func exit_state(old_state, new_state):
pass

func set_state(new_state):
previous_state = state
state = new_state

if previous_state !=null:
	exit_state(previous_state, new_state)
if new_state !=null:
	enter_state(new_state, previous_state)

func add_state(state_name):
states[state_name] = states.size()

It doesn’t have a var called id.

As the commentary above says, your node doesn’t have any id variable, what you’re trying to do with this line?