Attaching score value to enemy scene

I thought it would be cool to attach a point value to the enemy scene itself, in case we want to add different types of enemies in the future that are worth different amounts, and have each enemy keep track of its own value. I added the following code:

In enemy.gd, I added a variable for the points value and included it as an argument for the signal:

@export var value = 100
signal died(value)

Then passed the value argument when emitting the signal:

func die():
	queue_free()
	died.emit(value)

Then, in game.gd, I included value as a parameter in the _on_enemy_died callback function:

func _on_enemy_died(value):
	score += value
	print("Score: " + str(score))

Seems to work!

4 Likes

Good enhancement.

1 Like

Privacy & Terms