Attention | Topic was automatically imported from the old Question2Answer platform. | |
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:
emit_signal("no_health")
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.health
Stats.connect("health_changed", self, "set_hearts")
The connect()
message is a warning and can be ignored. Is Stats.gd 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, Stats.gd is on autoload. What is a possibility to fix it that my Stats.gd is _ready() at the time your heartsui is _ready()?
Godot9095 | 2021-08-06 10:45
With stats.gd being an autoload that rules out the _ready()
conjecture. The only things I can think of is:
label = null
e.g. yourLabel
doesn’t exist at$Label
- you are changing
health
from withinstats.gd
but you are usinghealth =
notself.health =
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