So, im trying to set a variable for the current amount of speed multiplier the player has based on the already existing base speed multiplier (which will be affected by the leveling system), in order to add things like speed potions and so on. The problem is that, for some reason, setting the current_movement_speed variable in the _ready function isn’t setting it! Meanwhile, the equivalent for the health (base health and current_health) is being set! Here is a preview of the code:
## Stats that will be changed by leveling up.
export_category("Base Stats")
export var base_health:int
export var base_movement_speed:int
## Stats that will be modified by both changes in the base stats, by itens modifiers or by other entities
export_category("Current Stats")
export var current_health:int = base_health
export var current_movement_speed:int = base_movement_speed
The _ready function of the Entity parent class:
func _ready() -> void:
current_health = base_health
current_movement_speed = base_movement_speed
printt("base health: %s | current health: %s " %[base_health,current_health])
printt("base movement speed: %s | current movement speed: %s " % [base_movement_speed,current_movement_speed])
You haven’t posted the full printout of this.
Also, if you set those variables to 10, 10 and what gets printed is 10, 10, where exactly is the problem?
base health: 10 | current health: 10
base movement speed: 0 | current movement speed: 0
What is getting printed is the difference between each variable, the 10 and 10 are of the health variables (which is the demonstration of what is expected to happen and that happens (as i noted), the “base movement speed: 0 | current movement speed: 0” is where the problem is at, because there is no difference in how I setup the code for the two sets of variables (health and movement speed)
There are two scripts in this case, the player script and the base_entity script. The player is an instanced scene of the Entity scene, which is a CharacterBody2D (the top node) with the base_entity script attached to it.
If exported properties are altered from the parent scene where this scene is instantiated into, then those values will override whatever you assigned to properties when editing the scene alone. So each scene you instantiate in the editor potentially deals with two sets of exported values. If you override “from the outside”, then changing it “from the inside” won’t have any effect. Check that.
Note that this has nothing to do with script class inheritance.
Great suggestion, but that also doesn’t seem to be the case. Now that I see, this only occurs with the Player. The enemy (which also extends Entity) seems to get its base_speed set.
Well unless I see your exact setup I won’t really be able to tell you what is happening. Exported variable initialization in general has nothing to do with _ready() as it happens before any of _ready() callback have been called and immediately after class constructors _init() have been called. So you need to have in mind the order of initialization and exported property overrides caused by scene instantiation.
If you can make a minimal reproduction project that demonstrates the problem and post it. Try to make it by reconstructing the situation from scratch in an empty project, may help you figure the problem out by yourself.
Yeah, thanks for the suggestion. Ended up doing that, everything went fine. Decided to just rename the current and base movement speed to just speed and it magically fixed the problem . Thanks for the help tho