Godot Version
4.5
Question
This is a script for my enemy damage indicator when you jump on it’s head you don’t take damage the handle danger function controls that the problem is that when its current health hits zero i get this error: “Invalid access to property or key ‘currenthealth’ on a base object of type ‘previously freed’.”
extends Area2D
func _on_body_entered(body: Node2D) -> void:
if body is PlayerController:
Bull.currenthealth -= 1
body.handle_danger(0,0.5)
print("off")
return
extends Node2D
class_name Bull_1
@onready var animated_sprite_2d: AnimatedSprite2D = $AnimatedSprite2D
@onready var currenthealth: int = maxhealth
@export var Speed = 40.0
@export var maxhealth = 3
var direction = -1.0
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
position.x += direction * Speed * delta
print("Bull: ", currenthealth)
if currenthealth <= 0:
_death()
func _on_timer_timeout() -> void:
direction *= -1
animated_sprite_2d.flip_h = !animated_sprite_2d.flip_h
func _death() -> void:
if currenthealth <= 0:
var tween = create_tween()
tween.tween_callback(self.queue_free)
you see it deletes itself