Godot 4 · GDScript
Achievements
Achievements you define in the panel and unlock from the game. Each has a key; hidden ones stay masked until the player unlocks them.
Panel Configuration
In the panel, create your achievements: name, description, icon, points, and whether each is hidden. Each one gets a key you use from code.
Save each achievement key: it is the identifier you pass to unlock_achievement() and check_achievement().
List with Progress
Get every active achievement with this player unlock state (hidden, still-locked ones are omitted). Arrives through achievements_loaded.
Gamdato.achievements_loaded.connect(_on_achievements)
Gamdato.list_achievements()
func _on_achievements(list: Array) -> void:
for a in list:
var mark := "[x]" if a.unlocked else "[ ]"
print("%s %s (%d pts)" % [mark, a.name, a.points])# achievements_loaded -> achievements: Array, each:
{
"achievement_key": String,
"name": String,
"description": String,
"icon_url": String,
"points": int,
"is_hidden": bool,
"sort_order": int,
"unlocked": bool,
"unlocked_at": String # null while locked
}Unlock an Achievement
Unlock one for the current player. Safe to call repeatedly: it never grants twice (it reports already_unlocked instead).
Gamdato.achievement_unlocked.connect(_on_unlocked)
Gamdato.unlock_achievement("first_win")
func _on_unlocked(ok: bool, key: String, already: bool) -> void:
if ok and not already:
print("Achievement unlocked: %s" % key)# achievement_unlocked(success: bool, achievement_key: String, already_unlocked: bool)
# already_unlocked = true when it was unlocked before (safe to re-call)
# achievement_checked(achievement_key: String, unlocked: bool, unlocked_at: String)
# unlocked_at is empty/null while still lockedUnlocking an inactive achievement fails (success=false). Unknown keys also fail.
Check or Inspect One
Ask whether a single achievement is unlocked, or fetch its full details (name, icon, points) plus the player state.
Gamdato.achievement_checked.connect(_on_checked)
Gamdato.check_achievement("first_win")
Gamdato.achievement_info_loaded.connect(_on_ach_info)
Gamdato.get_achievement_info("first_win")
func _on_checked(key: String, unlocked: bool, unlocked_at: String) -> void:
print("%s unlocked: %s" % [key, unlocked])