Godot Version
4.4.1
Question
I have created a HUD node. There are labels with default values there. The default value for coin counter is 0.
In the script ralated to the HUD node I have created a function to update the score once the character picks up a coin:
extends CanvasLayer
var score = 0
var hp = 3
@onready var coin_score_label: Label = $"coin score/coin score label"
@onready var hp_label: Label = $"hp/hp label"
func add_point():
score += 1
coin_score_label.text = str(score)
func take_damage():
hp -= 1
hp_label.text = str(score)
add_point function is used in the script the the Coin object
extends Area2D
@onready var hud: CanvasLayer = %HUD
@onready var animation_player: AnimationPlayer = $AnimationPlayer
func _on_body_entered(body):
hud.add_point()
animation_player.play("pickup")
The problem is that the default 0 value is still there and it is not overwritten by the above steps.
Also HUD is added ot the Autoload menu for the project