I want to create a class for my game that holds data for game characters:
extends Node
class_name AttributeSet
var max_health
var movement_rate
This class gets instanced so game entities can use it. However, I also want to refer to these variables in an interface-ish way, without having to access the instance. So far I've been using strings to refer to the variable name, but that leads to typos and isn't very elegant. I'd like something like this:
player.set_attribute(AttributeSet.health, 100) # this fails because 'health' is not a constant
I want to avoid this:
var player_attribute_set : AttributeSet = player.attribute_set
player.set_attribute(player_attribute_set.health, 100) # this works but it's cumbersome
or this:
player.set_attribute("health", 100) # leads to errors
Any ideas?