Skip to content

GDScript: Add Global Traits #107608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Conversation

SeremTitus
Copy link

@SeremTitus SeremTitus commented Jun 16, 2025

By using 'trait_name' in a .gd script file it becomes a global trait

trait_name Damageable
signal died

const MAX_HEALTH := 100
var health: int = MAX_HEALTH

func take_damage(amount: int) -> void:
	health -= amount
	print("Took damage:", amount, "Health now:", health)
	if health <= 0:
		died.emit()

func is_dead() -> bool:
	return health <= 0

func on_death()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants