12. Dictionaries and defaults
func run() -> Array:
var facts: Dictionary = {"unlocked": false, "attempts": 0}
facts["attempts"] += 1
facts["unlocked"] = true
var missing: Variant = facts.get("owner", "nobody")
return [facts["attempts"], missing, facts.has("unlocked")]A Dictionary stores values by key. Use get(key, fallback) when a key can be missing. has checks whether the key exists, even if its value is false or null. keys and values return arrays. erase removes a key/value pair.
A dictionary of action settings must keep the exact field spelling. characterId is not character_id. Native GDScript identifiers are case-sensitive, and dictionary keys are data; a plausible spelling does not automatically become a supported setting.
Typed dictionaries are available in current Godot 4 releases, but ordinary Dictionary is the clearest boundary for PCA’s JSON-style records and cross-language calls. Keep transferred values simple and document the expected keys.
