my Label doesn't update with the number of hearts.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Godot9095

Hello everyone,

I’m new to godot. And I’m currently adding HeartsUI, but continuously getting an error message about “The function ‘connect()’ returns a value, but this value is never used.”
What am I doing wrong?

Here is my code of my Stats.GD:

extends Node

export(int) var max_health = 120
onready var health = max_health setget set_health

signal no_health
signal health_changed(value)

func set_health(value):
	health = value
	emit_signal("health_changed", health)
	if health <= 0:

And here is the code of my HeartsUI.GD:

extends Control

var hearts = 120 setget set_hearts
var max_hearts = 120 setget set_max_hearts

onready var label = $Label

func set_hearts(value):
	hearts = clamp(value, 0, max_hearts)
	if label != null:
		label.text = "HP = " + str(hearts)
func set_max_hearts(value):
	max_hearts = max(value, 1)
func _ready():
	self.max_hearts = Stats.max_health
	self.hearts =
	Stats.connect("health_changed", self, "set_hearts")

The connect() message is a warning and can be ignored. Is an autoload? The only thing I can think of is that stats is not _ready() at the time your heartsui is _ready().

timothybrentwood | 2021-08-05 22:25

Yes, is on autoload. What is a possibility to fix it that my is _ready() at the time your heartsui is _ready()?

Godot9095 | 2021-08-06 10:45

With being an autoload that rules out the _ready() conjecture. The only things I can think of is:

  1. label = null e.g. your Label doesn’t exist at $Label
  2. you are changing health from within but you are using health = not = causing it to bypass the setter function.

timothybrentwood | 2021-08-06 14:25

Please, check if Label is inside/under another node.
Rename it.

smaran | 2021-08-06 19:40