Unreachable code issue

Godot Version

<stable4.2>

Question

<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:

@icon("res://entities/node/HitBox.svg")
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
	print("damage")

Hurtbox Script:

@icon("res://entities/node/HurtBox.svg")
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"):
		owner.take_damage(hitbox.get_damage())
	if owner.has_method("knock_back"):
		owner.knock_back()

Try this:

func get_damage() -> int:
	print("damage")
	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.