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

in Engine by (86 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.

by (3,503 points)
selected by

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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.