Godot 4 · GDScript · Currency & store
grant_currency
Applies a server-configured currency grant by reason key (quest payout, level-up bonus).
Signature
grant_currency(reason_key: String, idempotency_key: String = "") -> voidWhat it does
POSTs /currency/grant (session-auth). This is the generic reason-keyed grant path, distinct from rewards/claim (daily/periodic). On success result carries the full RPC payload (balances, applied amount, …). error_code may be grant_not_found / currency_inactive / cooldown_daily / cooldown_total / cap_exceeded / grant_failed / no_session / invalid_reason_key. Emits grant_completed(false, reason_key, {}, …) immediately on no session or an empty reason_key.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| reason_key | String | required | The grant's reason key configured in the panel (e.g. "quest_reward"). |
| idempotency_key | String | "" | Optional key to make retries safe so the grant is never applied twice; auto-generated if omitted. |
How to call it
Connect grant_completed first, then call grant_currency(). This is for in-game rewards, not real-money purchases (use buy_pack for those).
Result signal: grant_completed(success: bool, reason_key: String, result: Dictionary, error_code: String)
Example
Gamdato.grant_completed.connect(_on_grant)
Gamdato.grant_currency("quest_reward")
func _on_grant(ok: bool, reason_key: String, result: Dictionary, error_code: String) -> void:
if ok: print("granted! balances: %s" % result.get("balances"))
else: print("failed: %s" % error_code)Use cases
- Pay out currency when the player completes a quest.
- Award a level-up or first-login bonus defined in the panel (subject to cooldowns or caps).