- KinematicBody2D with attached script "Player.gd".
- Classfile named "State.gd". Gets instanced by Player.gd by preloading as variable "state" and calling state.new() on it.
- Classfile named "Substate.gd". Gets instanced by State.gd the same way Player.gd did it with State.gd.
Player.gd delegates _input and _process computation to State.gd which in return delegates them to the Substate.gd by calling the corresponding functions and passing event/delta.
If I understand the docs correctly, I should be able to call functions within the instanced classes, yet I get errors like "Nonexistent function "func_name" in base Nil.
Here are code examples for better understanding what I am trying to do.
onready var state = preload("State.gd").new()
onready var substate = preload("Substate.gd").new()
var speed = 100
var velocity = Vector2()
# set variables for directions (up, down, left, right)
# match event and set velocity according to it
# assign movement to velocity.normalized() * speed
From my understanding, this should work but I keep getting "nonexistent function" errors.
What is my mistake here or what have I misunderstood?