0 votes

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
Godot version 3.4.2
in Engine by (34 points)

1 Answer

0 votes

For transferring variables from one script to another in GDScript we tend to use singletons.
https://docs.godotengine.org/en/stable/tutorials/scripting/singletons_autoload.html

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

by (144 points)

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.