Godot Version
Most Recent
I don’t understand why I can’t reference it. I referenced it the same way in another part of the code.
Most Recent
I don’t understand why I can’t reference it. I referenced it the same way in another part of the code.
I know you said you did the same thing elsewhere in your code, but my initial guess is that the definition of deaths_label on line 6 isn’t doing what you’re wanting it to. It’s not an answer per se, but if I were you, I would try using get_child on DeathsLabel and see if that works. Or, you could try going about this using signals and on emit, pass the text that you want to change the label to
I am extremely new to Godot and haven’t coded for few years. I am not quite sure how to implement that.
While I was waiting for a response I tried something and it does what I want… its just… not very clean and I don’t why it works. Why do I get a reference sometimes but not all the time?
Could you show the function Deathcount.add_death()
?
Its in a global script so that - as the game resets on death.
This is it:
extends Node
var deaths = 0
func add_death():
Deathcount.deaths += 1
I wanted to update the label here but it seemed to be even harder as the label isn’t ever loaded in when the game resets.
You probably could put the label inside a Scene + death counter script. Autoload can take a script or a whole scene.
Do you have any other kill zones that are missing a label child? Maybe try adding to your ready test:
func _ready() -> void:
if deaths_label != null:
# etc, your print
else:
push_warning("I, %s am missing a death label!" % get_path())
make sure to paste scripts between three ticks for formatting like so
```
type or paste code here
```
I have these errors:
And the push_warning does not seem to show anything:
Okay, so I make a new scene - save and follow the same processes… I can try that.
Oh, I was looking in the wrong place. I have these errors now with the push_warning. In addition to the ones above.
I got it fixed. Thank you. I had to move the label into my Killzone scene because as you said… I had other killzones.
Okay, so that kinda solved it… except now all my enemies have a label with them as they move. I tried using label.queue_free() but it does not work as intended.
Another issue I have my deaths_label is placed in the level relative to where the killzones are.
I went back to checking for null. This does the job for now. I don’t understand why it checking it for the slimes when it is put right into the game. Its not in the killzone scene at all.
At this point I recommend moving your death label into the same scene as your “Deathcount” autoload. So many enemies doing the same thing will be a mess to organize and keep up.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.