#Death Count issue

137 messages · Page 1 of 1 (latest)

dire grove
#

extends Control
var player_die = false
var death: int = 0

func _process(delta) -> void:
$Number.text = str(death)
if player_die:
print(death)
death + 1
player_die = false
return

func deathcount():
player_die = true

Trying to add a death count on my player settings but feel like the count doesn't update directly or change the int = 0 when the player death. Yes i'm a rookie in gd code 😛

dense osprey
#

death += 1

dire grove
#

The print work correctly and update, that's the label who doesnt.

#

The call come from the player in the func die() and call the Deathcount in the global var name func deathcount()

#

I added the @onready var number: Label = $Number since it wasnt there but still doesnt change.

shrewd nexus
#

did you change death + 1 to death +=1?

shrewd nexus
#

can you move the print(death) statement to be after death += 1 and see what the output is?

dire grove
#

The output print correctly

dire grove
#

That's the change i made
extends Control
@onready var number: Label = $Number
var player_die = false
var death: int = 0

func _process(delta) -> void:
$Number.text = str(death)
if player_die:
print(death)
death += 1
player_die = false
return

func deathcount():
player_die = true

shrewd nexus
#

Is anything configured on $Number?

dire grove
shrewd nexus
#

can you try removing return at the end of your if statement?

dire grove
#

I did try and nothing change sadly

dire grove
#

So the print work because they are in the same if

#

cause if you change the var death: int = 0 to a different number it does the update and change the number in game for the $Number.text = str(death) .

#

just the death += 1 doesnt update the var death: int = 0

shrewd nexus
dire grove
#

Then everything look fine it just seems we are missing something..

shrewd nexus
#

I would think the return is causing an issue but you said you removed it and it still happens. From what I'm seeing here, there should be no issue..

dire grove
#

I changed everything for something less complicated.
@onready var number: Label = $Number
var death: int = 0

func _process(delta: float) -> void:
$Number.text = str("Count: %s") % death

func deathcount():
death += 1
print(death)

#

Everything do the same as before, but still doesn't update in game.

shrewd nexus
#

i have the same thing going on in my game and it works

#

func _process(delta: float) -> void: #This will show the ammo depending on the weapon that is active if AmmoManager.active_weapon == "1903": var AmmoCounter = str(AmmoManager.ammo_in_magazine, "/", AmmoManager.ammo_in_inventory) %ammo.text = AmmoCounter

dire grove
#

Oh wait..

shrewd nexus
#

maybe there is a scope issue

#

I think you're thinking the same thing but maybe try declaring the death var in the if statement

dire grove
shrewd nexus
#

yeah

#

did you have any errors or anything else in your Output or Debugger?

dire grove
#

Nothing

dire grove
#

Since the if is a different scope. So i added everything inside. $Number.text = str(death) and the var death: int = 0 but doesnt do anything

shrewd nexus
dire grove
#

and since the func _Process only update when the if player_die is true.. well the $Number.text = str(death) doesnt update anymore.

dire grove
#

It just weird that the print(death) work correctly

shrewd nexus
#

can you also put $Number.text = str(death) inside the if statement, after the print?

dire grove
#

Same issues, the print stay correctly but doesn't update the text.

shrewd nexus
#

can you print(death) before the if statement?

#

see what you get

dire grove
#

Same the print write in the output how much dead I got.

shrewd nexus
#

Okay. I'm thinking the issue is that the $Number has no access to this node's variables

#

Can you try to create a new autoload/global script that just contains var death: int = 0?

#

so then instead of doing $Number.text = str(death) in this script, you'll be doing $Number.text = str(Deathcount_script.death)

#

and to update the death count, you'd do Deathcount_script.death += 1 instead of death += 1

dire grove
#

I tried something different and remove out the if player_die and now the death += 1 update the $Number.text = str(death) but infinitly

shrewd nexus
#

yeah definitely sounds like a scope issue then

#

I'd give it a try with a global script containing the deathcount variable, I think that'll do it

#

that's how mine is set up and it works

#

you'll be able to reference the deathcount from different scenes as well if needed in the future if it's a global var

dire grove
#

So this is only a normal node with a script with var death: int = 0 inside

shrewd nexus
#

Is it in the same scene as $Number?

dire grove
#

No

#

I made a new scenes

shrewd nexus
#

Oh, That’s definitely the issue then

#

Scenes can’t go to other scenes and access variables, they aren’t global

dire grove
#

No the Deathcount is a global scenes.

#

So the Player can call the func when he died.

shrewd nexus
#

Oh so the player calls the deathcount() func when it dies?

dire grove
#

Yeah

#

Then the player_die = true
So inside the _process it call (Oh! i died) and do the death += 1 and call player_die = false back.

shrewd nexus
#

Got you. Yeah I’m understanding this correctly, just making sure

#

How would you feel about moving the death+=1, print, and player_die = false to the deathcount() function? There’s no need to set it every frame since it’s triggered by a function anyways. Plus it’ll simplify the troubleshooting here

#

Probably don’t even need the player_die variable at all. Just increment the death count in the deathcount() function

dire grove
#

Something like that?

shrewd nexus
#

Yeah, I’d throw in a print(death) in the deathcount() just to make sure it’s working but yeah

dire grove
#

gdlament the label doesn't update.

shrewd nexus
#

If you print(death) in the process function is it still correct?

dire grove
shrewd nexus
#

Can you send a screenshot? Not sure I’m understand that right

dire grove
#

If i change the var death: int = 0 to a different number it write
(544) 1 exemple.

shrewd nexus
#

What is that lol. I thought it should be printing the current value of death every frame, which would be once per line in the output log

dire grove
#

It count the str i think..

shrewd nexus
#

Can you show the code you have as of right now?

dire grove
#

extends Control
@onready var number: Label = $Number
var death: int = 1

func _process(delta: float) -> void:
$Number.text = str(death)
print(death)

func deathcount():
death += 1

#

Or wait this is reversed it count (death) over time but the str stay 1

shrewd nexus
#

It should be printing your death var which is a integer

dire grove
#

That's what i thought too

#

but if i add dead += 1 inside the _process the other number should go up too

shrewd nexus
#

I don’t think I’ve ever seen the parenthesis thing when printing like that

#

can you do a print($Number.text) in the process function?

#

instead of print(death)

dire grove
#

Same (2) 0 and the 0 increase over time.

#

if I remove the death += 1 inside the _process

#

the (0) increase over time.

shrewd nexus
#

can you try to add another var in? ```extends Control
@onready var number: Label = $Number
var death: int = 1
var new_death_count

func _process(delta: float) -> void:
$Number.text = new_death_count
print(new_death_count)

func deathcount():
death += 1
new_death_count = str(death)

#

maybe the issue is trying to convert the death var as an int directly to a string for the text? Idk, try that^ and see what happens

#

my head hurts but I'm in too deep now to stop

#

probably could statically type the new_death_count as a str but I left it dynamic just for some leeway

dire grove
#

Invalid assignment of property or key 'text' with value of type 'Nil' on a base object of type 'Label'

shrewd nexus
#

what line?

dire grove
#

$Number.text = new_death_count

#

and the output write
(3708) <null>

dire grove
shrewd nexus
#

I guess try $Number.text = str(new_death_count) instead

dire grove
#

And the output say (840) <null>

#

Cause the (0) goes up over time.

#

It fix when telling new_death_count = death

dire grove
#

I guess the (0) that increase over time is the (delta: float)

#

So when you add a if and add print(death) the delta doesnt count anymore.

#

So that's why it doesnt show up.

shrewd nexus
#

oh, interesting. I didn't know that

#
extends Control
@onready var number: Label = $Number
var death: int = 1

func _process(delta: float) -> void:
    var new_death_count = str(death)
    $Number.text = new_death_count
    print(new_death_count)

func deathcount():
    death += 1

maybe this

#

running out of ideas lmao

dire grove
#

Yeah this is complicated for something like this.
i tried and the still (0) 0 and the death += does update the print

#

and the (0) goes up over time.

shrewd nexus
#

The only other thing I can think of to do is to rewrite some stuff.

Make the label into its own scene, make sure it’s not global, and have a script attached to its root to update its text. Basically what you have here but break out part of it so that the only thing global is just the death count. Maybe rename the “Number” node just incase that isn’t a valid name

#

So the new script would just reference the global script’s death variable and convert it to a string for the Number’s text like you’re currently trying to do

#

I can share exactly how everything is on my stuff that works later if that doesn’t work, but if you set it up that way it’ll be pretty close

dire grove
#

Instead of just making a global scene totaly seperated i just added directly inside the Exit_Game menu .. where i want it and just make it part of the scenes.

shrewd nexus
#

So you just added the death count into an already existing global script instead of making a new one?

dire grove
#

Yeah

shrewd nexus
#

That’s awesome, nice! Glad we got it figured out lol

dire grove
#

I just recreate a Control node with label and just added your script with the func link between the player and the main node inside the Exit_game scene.

dire grove
shrewd nexus
#

Sweet..no problem! Even though it was probably something small and stupid we were missing, this is the kind of stuff that I learn a lot with so it’s worth it

#

I like digging into stuff even if it’s over something that seems small like a death counter haha. It do be like that sometimes

dire grove
#

I do not know why it was doing that.. Feel like a lost somewhere not knowing the issues but yeah glad to see it finaly work haha

#

The only idea i have that's making the issues is .. A global event inside a global event.

#

Cause adding the global event inside the pause menu that is already a global event.

#

But if it was that.. Well i learn something

#

Global event in Global event = NO!