Complete Godot 4 Game Developer 2D Online Course - Error in the code

Hello, I am going through the Godot class and I receive always an error regarding calling a function that anyway is created (I think) and this is stopping me from continuing the lessons. Can you please take a look?

See codes and screenshots

hud script

extends Control

@onready var score = $Score

func set_score_label(new_score):
	score.text = "SCORE: " + str(new_score)

game script

extends Node2D

var lives = 3
var score = 0

@onready var player = $Player
@onready var hud = $UI/HUD

func _ready():
	hud.set_score_label(score)
	

func _on_deathzone_area_entered(asteroide):
	asteroide.die()

func _on_player_took_damage():
	lives = lives - 1
	if lives == 0:
		print("Game Over")
		player.die()
	else:
		print(lives)
	
func _on_enemyspawner_enemy_spawned(enemy_instance):
	enemy_instance.connect("died", _on_enemy_died)
	add_child(enemy_instance)

func _on_enemy_died():
	score += 100
	hud.set_score_label(score)

When then I did not received the regarding the function, I had one saying that the line score.text = "SCORE: " + str(new_score) was wrong, however is the same as the video.

Thank you for your help



Hi and welcome to the community :wave:

Sorry i missed this yesterday.

Just looking, at first glance, it doesn’t appear that the hud.gd script is attached to the HUD node.

are you able to check it if is please? let us know if that was the cause of the error

Cheers

Darren

Hey Darren,

thank you for your help!

You are completely right… I think that I needed more coffee that day… such a silly mistake was driving me crazy!

All solved, thank you!

1 Like

aha, sweet, glad its all working and gets you back on the learning track :slight_smile:

I’ve had similar on more than one occasion where i cant see what I’ve done and needs a fresh pair of eyes from me going demented staring at the screen pulling out what’s left of my hair lol

anytime, glad to help where I can.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms