Hello,
I have a function in my code to apply damage to the health of a creature. However, the changes to the current_creature_health variable do not persist outside of the function, when it is called again it begins from the creatures maximum health rather than the damaged health from the previous call.
I've managed to strip away all but the offending lines of code that still repeat the issue. Normally the function would only be called once elsewhere in code, but here the function is called repeatedly in Process and prints the following output.
To my eyes the function should call repeatedly until its in the negative and just keep going. but it keeps starting again from the max health stored in the resource. Plugging the stats directly into the function does work as intended, but defeats the point of having a reusable function.
Any ideas?
extends Node3D
@export var creature : creature_resource # Resource that contains Creature Stats
var current_health : int # Variable to store health
func _ready():
current_health = creature.health() # Assign health the Variable (87)
func _process(delta):
damage_func(current_health)
func damage_func(health):
var damage_hp = 25 # Fixed value in place of damage calculation
print("defender_health B: %d" % health) # Health before Damage
health -= damage_hp # Subtract from HP
print("defender_health A: %d \n =====" % health) # Health After Damage
Output:
defender_health B: 87
defender_health A: 62
defender_health B: 87
defender_health A: 62