Godot Version
4.7.2
Question
I’m trying to put together a little pokemon clone as a learning project, but I’m having some trouble figuring out how to store stats. I have a resource set up that contains all the stats they’ll need, shown below:
I have the monster’s Base_Stats, as well as a random modifier (Gene_Stat) which would be randomized for every individual monster to give them some variance. The stat that would be shown to the player and used in battles is Current_Stat, which is derived from a formula shown at the bottom. For testing, I also have the monster’s Level as a derived stat which is their XP divided by 100.
extends Resource
class_name Creatures
@export var Creature_Name = "PLACEHOLDER"
@export var Model = "placeholder"
@export var Tex = "placeholder"
@export var Type = TYPE.Normal
@export var Base_Atk = 100
#IVs
@export var Gene_Atk = 0
@export var Xp: int = 1
enum TYPE {Normal, Fire, Water, Grass, Test, Etc}
#So the goal here is that Level is derived from Xp
#and the current_stats are derived from the other ones,
#so you don't set them manually ever
#assuming that this is how resources work
@warning_ignore("integer_division")
var Level = Xp / 100
@warning_ignore("integer_division")
var Current_Atk = (Level / 50) * Base_Atk * Gene_Atk + 5
#Add 5 so it's not super low at level 1
To try and make sure that these derived stats (Level and Current_Stat) were actually working, I created a button, customized the Base_Stat, Gene_Stat, and XP in the inspector, and tried to have the button print the monster’s derived stats and name.
extends Button
@export var stats: Creatures
func _ready():
var button = $"."
button.text = "Click me"
button.pressed.connect(_button_pressed)
add_child(button)
func _button_pressed():
print(stats.Level)
print(stats.Current_Atk)
print(stats.Creature_Name)
The issue is that it always prints
0
5
fella
The name is working properly, but it seems that it’s not deriving the level from the XP value and formula I set in the inspector. Currently, no value for any of the stats causes the numbers it prints to change. Have I set up the equation wrong, or is this an incorrect way to use resources? Should I be exporting the derived stats too, even though they’re not meant to be changed manually?