GDscript inheritance pass values to derived for a statemachine

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

Hi.

I would like to do a StateMachine with GDscript but when the state is on Idle for example, does not recognize the variables from the base class.

# Base
#get the player class: 
class_name PlayerSMF
onready var pl = find_parent("Player") as Player

onready var PlayerIdle = load("......").new()
...

#Derived
# How I can get the pl variable?
extend PlayerSMF
# Statemachine methods
EnterState():
ExitState():
UpdateState():
# I need to use the pl variable here
GetTransition():
# I need to use the pl variable here
:bust_in_silhouette: Reply From: Noddy

For transferring variables from one script to another in GDScript we tend to use singletons.

They are just scripts or scenes that can be referenced anywhere. I hope this helps, good luck.

Thank you, but I want to avoid this kind of methods.

Cristian | 2022-02-11 21:02