Why a variable isn't stored/updated correctly

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

Hi all,
i have a function that add value to a variable and another variable that is the sum of 2 variables.

When i use the function to add value the value isn’t stored correctly and i can’t figure why.

Here are the variables and the function:

var damage = 1
var attdam = 1
var total_damage = damage + attdam

func buy_attdam():
attdam = attdam + 1

and here the full code on Pastebin:

Someone can kindly explain why the total_damage variable stays always at value = 2 even if i use the function buy_attdam? Thank you

:bust_in_silhouette: Reply From: Thakee Nathees

you never change the value of the total_damage after you declared it.
in the function but_attdam() you only change the attdam variable which is not effect the total_damage unless you change it.

Thank you.

Now i feel a bit ashamed.

Kiren | 2020-04-10 17:49