Problem with adding stats

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Maciu01

In my game i want to add training sessions, where player can earn some strength points
(you can earn 5, 10 or 15 points). Strength can improve the damage , in code i divided the strength by half and that adds to the damage. My problem is when I for example
get 5 strength points and that adds 2 damage, but when i train again and i get another 5 strength points I now should get 5 damage points because now i have 10 strength, instead I get 7 points, because it adds the first 5 with the second 10.

func _ready():
strength = 0
Damage = 20


func change_strength(amount):
strength += amount

func update_damage():
Damage += strength / 2

func point_reward():
if score >= 20:
	PlayerStats.change_strength(+5)
if score >= 40:
	PlayerStats.change_strength(+10)
if score >= 60:
	PlayerStats.change_strength(+15)
	
:bust_in_silhouette: Reply From: jgodfrey

Seems like rather than accumulating the strength, you just want to use it - as passed. If that’s the case, change this:

func change_strength(amount):
    strength += amount

to this…

func change_strength(amount):
    strength = amount

So, don’t add amount to the current value. Just assign amount as the current value.