Barbarian Blaster - Enemies damaging Base

Hi everyone!

I’m working through the Godot 3D course and am stuck on the Health and Labels lesson for Barbarian Blaster. I think I have everything set up correctly, but when I test my game, the Base loses health to quickly and the game resets in less than a second. Any ideas why this might be happening? Code below:

base.gd:

extends Node3D

@export var max_health: int = 5

var current_health: int:
set(health_in):
current_health = health_in
print(“health was changed”)
$Label.text = str(current_health)
if current_health < 1:
get_tree().reload_current_scene()

@onready var label: Label = $Label

func _ready() → void:
$Label.text = str(max_health)

func take_damage() → void:
print(“damage delt to base!”)
current_health -= 1

enemy.gd:

extends PathFollow3D

@export var speed: float = 2.5

@onready var base = get_tree().get_first_node_in_group(“base”)

func _process(delta: float) → void:
progress += delta * speed
if progress_ratio == 1.0:
base.take_damage()

At the moment, you aren’t freeing the enemies with queue_free() once they have damaged the base, nor are you stopping their _process() functions with set_process(false), so as soon as an enemy reaches the Base, it will call base.take_damage() every frame. These modifications will be covered in the lecture content very soon, if you haven’t seen them already, to solve exactly this problem =)

Also, just for future reference, whenever you post code, please format it as actual code so that the indentation is preserved. GDScript code changes scope (and therefore meaning) depending on the level of indentation, so it’s harder to read when you post it as plaintext.

Here in the forum, you can denote a codeblock, like this, by bookending your code in three '''apostrophes''' (the one on the ~ key). In the Q&A, there is a [<>] button in the toolbar instead.

1 Like

Thanks allot for the reply.

1 Like