Godot Version
4.4
Question
I’m trying to setup an entity base that setup the entity stats from an autoload dictionary. The idea being that on various enemy classes than inherit from this base I would pass in the enum type to the setup function to initialise the stats. I haven’t even used the function yet but even trying to run the game it keeps giving the following error:
Parser Error: Could not resolve member “enemy_type_data”: Cyclic reference.
on this line:
health = EnemyStatsGlobal.enemy_type_data[enemy_type][“health”]
Entity Base
extends CharacterBody3D
class_name EntityBasevar health : int
var damage : int
var move_speed : float
var rotate_speed : floatenum EnemyType {
BASIC,
TURRET,
THING
}func setup_enemy_stats(enemy_type : int) → void:
health = EnemyStatsGlobal.enemy_type_data[enemy_type][“health”]
damage = EnemyStatsGlobal.enemy_type_data[enemy_type][“damage”]
move_speed = EnemyStatsGlobal.enemy_type_data[enemy_type][“move_speed”]
rotate_speed = EnemyStatsGlobal.enemy_type_data[enemy_type][“rotate_speed”]
pass
My global / autoload enemy_stats
extends Node
class_name EnemyStatsENEMY MODEL DICTIONARY
var enemy_type_data: Array[Dictionary] = [
{
“scene”: preload(“res://scenes/enemies/enemy_basic.tscn”),
“health”: int(10),
“damage”: int(2),
“move_speed”: float(1.0),
“rotate_speed”: float(0.5)
},
]
I’m very much learning Godot so if there is a better way to do this I’'m all ears.