0 votes

Hi ! I got a little trouble when making this turn based project : Whenever my projectile is hitting the target, hp of said target will go down (did it with a double print(hp) before and after the impact), but the progress bar and the label will not actualize themselves. I think that the setget isn't working somehow and can't figure out why.

Will gladly take any help !

Here is a miniature project

asked Jun 29 in Engine by Rensae (57 points)

1 Answer

+2 votes
Best answer

The problem is that you are setting the hp from inside the script with the setter defined. Setters and getters only works from ouside. If not, when you try to set the hp inside the setter, it will call again the setter and again and again (stack overflow). So, if you want to call the setter from inside the same script, you just have to call it as any other method, or use self. In your Enn1.gd, simply change:

hp -= Global.damage
or to this if you want something more similar to what you've done:
self.hp -= Global.damage

To make it clear: the setter will only be called if you set the variable from other script, like if in your player scene call enemy.hp -= damage or something similar.

answered Jun 29 by p7f (2,654 points)
selected Jun 29 by Rensae

Thanks a lot ! I understand now :)
Edit : It seems to work, but the value of my progress bar doesn't seem to change, am I misstyping something ?

I got this whit the code i gave you

Isn't that bar the one which you needed to update?

Oh it worked for you ? Strange... I did it with a texture progress bar, but it doesn't work

Whith that very same project you shared me it doesnt work for you?

Yeah, I tried to replace progress bar by a Texture progress bar to see, but it doesn't seem to work

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.