ゲームのアイデアと機能

次に追加する機能

プレイヤー受信箱

個別通知とプロジェクト一斉配信を、保護された報酬と共通のソーシャルポーリングで扱います。

SDK:developプレイヤーセッションが必要
Godot
プレイヤー受信箱のイラスト
確認できる結果

ゲームが個別通知と一斉配信を表示し、既読にして、保護された各報酬を最大一度だけ受領します。

動画は後日公開

この手順の動画はまだありません。ガイドとMCPへの依頼は利用できます。

プレイヤー受信箱

同じプロジェクトを準備する

  1. ゲームの設定と同じプロジェクトをダッシュボードで選択してください。

    プレイヤー受信箱 →
  2. 最初のリクエストに追加の定義は不要です。対応するゲームデータがなければ、空の結果も正常です。

    このプロジェクトでテキスト一斉メッセージを公開する前にテストプレイヤーを登録します。同じプレイヤーで受信箱を読みます。

    公開時点までに登録済みで、現在アクティブなプロジェクトのプレイヤーが対象です。以前非アクティブだったプレイヤーも再有効化後に対象となり得ます。公開後の新規登録は対象外です。

この機能を実装する

ガイドは閲覧できます。実行には有効なプロジェクトキーが必要です。 プロジェクトを準備する

SDK をインストールし、プロジェクト設定をインポート済みで、プレイヤーがログインしていること。

この SDK サンプルは develop を使用します。必要な API がインストール済みの SDK にあるか確認してください。

クイックスタートで対象プレイヤーを接続します。ボタンやシーンの明示的な操作からrun_reviewed_action()を呼び出してください。ファイルを開くだけではリクエストは送信されません。

GDScript
res://scripts/inbox.gd
horizOn 呼び出し
1extends Node
2​
3# Existing configured SDK and authenticated player session required.
4# Invoke run_reviewed_action explicitly after reviewing this example.
5func run_reviewed_action() -> void:
6 if not Horizon.auth.isSignedIn():
7 return
8 var user_id: String = Horizon.auth.getCurrentUser().userId
9 var loaded: Dictionary = await Horizon.inbox.getInbox(user_id, "")
10 if not loaded.success:
11 push_error(loaded.errorCode)
12 return
13 for entry in loaded.data.entries:
14 print(entry.textKey)
15 # The SDK materializes unchanged responses from its project/player cache.
16 # Respect loaded.data.pollAfterSeconds and stop refreshing with the game lifecycle.
17​
18 var claim_state := {"busy": false}
19 var claim_selected = func(entry_id: String) -> void:
20 if claim_state.busy:
21 return
22 var project_id := "YOUR_PROJECT_ID"
23 var path := "user://inbox_claim_" + project_id + "_" + user_id + ".txt"
24 if FileAccess.file_exists(path):
25 var previous := FileAccess.open(path, FileAccess.READ)
26 if previous == null:
27 return
28 var pending := previous.get_as_text()
29 previous.close()
30 if pending != entry_id:
31 return # Resolve the original claim first.
32 else:
33 var current: Dictionary = Horizon.inbox.getCurrentInbox()
34 if current.get("userId", "") != user_id:
35 return
36 var selected: Dictionary = {}
37 for entry in current.get("entries", []):
38 if entry.id == entry_id:
39 selected = entry
40 break
41 if selected.is_empty() or selected.claimed:
42 return
43 var attachment = selected.get("attachment")
44 if not attachment is Dictionary or attachment.get("values", []).is_empty():
45 return
46 # An existing identical pending ID bypasses this new-selection guard for safe replay.
47 var file := FileAccess.open(path, FileAccess.WRITE)
48 if file == null:
49 return
50 file.store_string(entry_id)
51 file.flush()
52 var saved_ok := file.get_error() == OK
53 file.close()
54 if not saved_ok:
55 return
56 claim_state.busy = true
57 var claimed: Dictionary = await Horizon.inbox.claim(user_id, entry_id)
58 claim_state.busy = false
59 if not claimed.success:
60 push_error(claimed.errorCode)
61 return
62 # Display claimed.data.inbox and replace values with claimed.data.playerValues.
63 # Never add the reward delta locally.
64 var current := FileAccess.open(path, FileAccess.READ)
65 if current != null:
66 var still_pending := current.get_as_text() == entry_id
67 current.close()
68 if still_pending:
69 DirAccess.remove_absolute(ProjectSettings.globalize_path(path))
70 # Bind claim_selected to an explicit player action; do not claim automatically.
71 # Retry the same saved entry_id after an uncertain response.
72 # Other deliberate actions: await Horizon.inbox.markRead(user_id, entry_id)
73 # await Horizon.inbox.remove(user_id, entry_id) # Protects unclaimed rewards.
完全なSDKサンプルを開く ↗

新しい機能をテストしましょう。

ゲームが個別通知と一斉配信を表示し、既読にして、保護された各報酬を最大一度だけ受領します。

ゲームの設定と同じプロジェクトをダッシュボードで選択してください。

エンドポイント
  • GET/inbox
  • POST/inbox/read
  • POST/inbox/claim
  • POST/inbox/remove
API リファレンスのすべてのエンドポイント
リーダーボードのイラスト
次のステップへのおすすめ

毎ラウンドにハイスコアを。

ラウンド終了後にスコアを保存し、上位のプレイヤーを表示します。現在の接続とプレイヤーセッションを引き続き使用します。