Unreachable code issue

Godot Version



<Hi. Im making hitbox and hurtbox classes, and getting Unreachable code (statement after return) in function "get_damage()". error inside hitbox class script. I would appreciate if you could teach me how to solve problem. also, i am still not sure how exactly to use hitbox hurtbox classes. Since hitbox class script will be shared among all attached nodes, how would I have different damage value for different enemies?

Hitbox script:

class_name HitBox
extends Area2D

@export var damage := 10

func _ready():
	pass # Replace with function body.

func get_damage() -> int:
	return damage + randi() % 7 - 3

Hurtbox Script:

class_name HurtBox
extends Area2D

func _ready() -> void:
	connect("area_entered", _on_area_entered)

func _on_area_entered(hitbox: HitBox) -> void:
	if owner.has_method("take_damage"):
	if owner.has_method("knock_back"):

Try this:

func get_damage() -> int:
	return damage + randi() % 7 - 3

return has the effect, that the function returns immediately and no code afterwards is executed. If you put code afterwards, then that code will not be executed at all. This warning just notifies you, that you have code (in your case print("damage")), that will never be executed.

seems like the cause of issue isnt that.
func take_damage() also seems like not working since bothe print(“take damage”) and print(“damage”) not showing.