0 votes

Hello Godot community, my variable that I created isn't storing the updated value. I have made a variable death_count with value 0 and it s supposed to increase everytime my player health reaches 0, but it's always stuck on 1 and I don't know why it is happening.
Take a look at my dead function :

func dead(): 
    if playerhp==0:
        death_count +=1 // It's not getting incremented
        print("player with 0 health")
        if emit == false:
            $Particles2D.emitting = true
            #emit = true
        Engine.time_scale = 0.2
        $CollisionShape2D.disabled = true
        print("Dead Function")
in Engine by (416 points)

1 Answer

0 votes


what do you mean with

it's always stuck on 1

Could it be that you never go to playerhp == 0 twice?
Then you could just if playerhp <= 0:

by (107 points)

I figured out that the number isn't increasing because I am usingget_tree().reload_current_scene()when my player dies. Do you have any idea how to increment death_countwith this ? Seems like the variable is not able to store it's previous information when the scene gets reloaded.

You can use Global Variables to store the data.
In godot u can use Singletons

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.