Справочник функций
Godot 4 · GDScript · Rewards
claim_reward
Claims a reward by key (safe against double-claims).
Asynchronous (result via signal)
Signature
claim_reward(key: String, idempotency_key: String = "") -> voidWhat it does
POSTs /rewards/claim (session-auth). Idempotent: an auto-generated idempotency_key is used when you omit it, so a retried claim never grants twice (a replay still reports success). payload is the full server response (payload_keys, currency_grant.balances, period_key, etc). On failure error carries a code such as cooldown, already_claimed_period, or expired; calling with no active session emits no_session and an empty key emits invalid_key.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| key | String | required | The reward key from get_rewards_status(). |
| idempotency_key | String | "" | Optional; auto-generated if omitted so retries never double-grant. Pass your own (e.g. persisted to disk) for retry-safety across app restarts. |
How to call it
Connect reward_claimed first, then call claim_reward().
Result signal: reward_claimed(success: bool, reward_key: String, payload: Dictionary, error: String)
Example
Gamdato.reward_claimed.connect(_on_claimed)
Gamdato.claim_reward("daily_login")
func _on_claimed(ok: bool, key: String, payload: Dictionary, error: String) -> void:
if ok: print("claimed %s" % key)
else: print("no: %s" % error)Use cases
- Claim the daily login bonus.
- Hand out a periodic reward from the game UI.