Godot Version
4.3
Question
I have a SkillDB.gd, a singleton database file for my character skills:
extends Node
enum Skill_id { INSIGHT, POWER_SLASH, BASH }
const skill_dictionary : Dictionary = {
"Insight" : Skill_id.INSIGHT,
"Power Slash" : Skill_id.POWER_SLASH,
"Bash" : Skill_id.BASH
}
const skill_res : Dictionary = {
Skill_id.INSIGHT : "res://Skills/Insight.tres",
Skill_id.POWER_SLASH : "res://Skills/Power_Slash.tres",
Skill_id.BASH : "res://Skills/Bash.tres"
}
And I have made my skill class for custom resources as the following:
extends Resource
class_name SkillClass
@export var name: String
@export var power: int
@export var cost: int
@export var accuracy: int
@export var active: bool
@export var description: String
@export var skill_id : SkillDB.Skill_id
func _ready():
_set_skill_id()
func _set_skill_id():
skill_id = SkillDB.skill_dictionary[name]
func get_skill_id() -> SkillDB.Skill_id :
return skill_id
The _set_skill_id() method is called to initialize the skill_id accordingly to the SkillDB.
However when I checked the result, the skill_id is always set to 0 and not to the skill I created the resource for.
Why is this happening?