Godot Version
4.7.stable
Question
Hi, I’m currently making a buffing subsystem as a part of my pet project. I currently have a Stats class that has a BUFFABLE_CATEGORIES enum and variables that each match one of the enum entries.
@tool
extends Node
class_name Stats
enum BUFFABLE_CATEGORIES {
HEALTH,
STAMINA,
ATTACK,
DEFENSE,
SPEED,
}
@onready var health: HealthComponent = get_node_or_null("HealthComponent")
@onready var stamina: StaminaComponent = get_node_or_null("StaminaComponent")
@onready var attack: AttackComponent = get_node_or_null("AttackComponent")
@onready var defense: DefenseComponent = get_node_or_null("DefenseComponent")
@onready var speed: SpeedComponent = get_node_or_null("SpeedComponent")
In the StatBuff class, I want to make a way to add stat buffs to each class, which each has different values amount and names.
Example:
extends StatComponent
class_name AttackComponent
enum BUFFABLE_STATS {
PHYSICAL,
MAGICAL,
}
@export var base_phy_attack: int = 10
@export var base_mag_attack: int = 10
var physical: int = 10
var magical: int = 10
and
extends StatComponent
class_name SpeedComponent
enum BUFFABLE_STATS {
ATTACK,
CAST,
MOVEMENT,
RUN_MULT,
JUMP_FORCE,
FAST_FALL_MULT,
AIR_SPEED_MULT,
}
@export_group("Combat")
@export var base_attack_speed: float = 1.0
@export var base_cast_speed: float = 1.0
@export_group("Movement")
@export var base_move_speed: float = 750.0
@export var base_run_mult: float = 2.0
@export var base_jump_force: float = 2000.0
@export var base_fast_fall_mult: float = 2.0
@export var base_air_speed_mult: float = 1.25
var attack: float = 1.0
var cast: float = 1.0
var movement: float = 750.0
var run_mult: float = 2.0
var jump_force: float = 2000.0
var fast_fall_mult: float = 2.0
var air_speed_mult: float = 1.25
Now, to the matter at hand. in the StatBuff class, I want to have a dropdown menu to select which stat category to buff, and then, based on that dropdown’s value, the second dropdown changes automatically to the correct enum values of the respective class’ BUFFABLE_STATS.
I know that this is possible, but I can’t figure out how…
Something like:
extends Resource
class_name StatBuff
@export var category: Stats.BUFFABLE_CATEGORIES
@export var stat: Stats[category].BUFFABLE_STATS
@export var buff_amount: float
@export var buff_type: BuffType
Obviously, that var stat is gonna error, my question is how to do it correctly.
Pretty please? ;u;



