你的下一项功能
玩家统计
按会话批量上报回合数、击败数和最佳成绩,支持求和、最大值、最小值或最新值规则。
Godot

可见的结果
游戏在一个批次中上报完整会话,并显示当前计数器和周期。
此步骤尚无视频。指南和MCP请求已可使用。
玩家统计
准备同一个项目
在仪表盘中选择与游戏配置相同的项目。
玩家统计 →在控制台表单中创建或复用这些测试条目。这些是示例值,并非项目当前数据。
- 统计定义
kills: mode=sum, reset=none; best_score: mode=max, reset=none
求和会累加每次上报。最大值和最小值保留极值;最新值直接替换。最大值、最小值和最新值均由首次上报初始化。数值必须是安全范围内的有符号整数。
运行示例前先保存、重新加载并核对条目。保留其他定义。
实现此功能
你可以预览指南。运行需要有效的项目密钥。 准备项目
已安装 SDK、导入项目配置,且玩家已登录。
此 SDK 示例使用 develop。请检查已安装的 SDK 是否具备所需 API。
先通过快速入门连接目标玩家,再通过明确的按钮或场景操作调用run_reviewed_action()。仅打开文件不会发送请求。
GDScript
1extends Node
2
3# Existing configured SDK and authenticated player session required.
4# Invoke run_reviewed_action explicitly after reviewing this example.
5# This explicit action reports the shown persisted batch.
6func run_reviewed_action() -> void:
7 if not Horizon.auth.isSignedIn():
8 return
9 var snapshot: Dictionary = await Horizon.statistics.getStatistics()
10 if snapshot.is_empty():
11 push_error(Horizon.statistics.getLastErrorCode())
12 return
13 var pending_path: String = "user://statistics_" + snapshot.userId + ".dat"
14 var pending: Dictionary
15 if FileAccess.file_exists(pending_path):
16 var file := FileAccess.open(pending_path, FileAccess.READ)
17 if file == null:
18 return
19 var saved: Variant = file.get_var()
20 file.close()
21 if not saved is Dictionary:
22 return
23 pending = saved
24 else:
25 pending = {"operationId": Horizon.statistics.createOperationId(),
26 "updates": [{"key": "kills", "value": 3}, {"key": "best_score", "value": 250}]}
27 var file := FileAccess.open(pending_path, FileAccess.WRITE)
28 if file == null:
29 return
30 file.store_var(pending, false) # Variant storage preserves int64 values.
31 file.flush()
32 var saved_ok: bool = file.get_error() == OK
33 file.close()
34 if not saved_ok:
35 return
36 var original_bytes: PackedByteArray = FileAccess.get_file_as_bytes(pending_path)
37 if original_bytes.is_empty():
38 return
39 var result: Dictionary = await Horizon.statistics.updateStatistics(pending.updates, pending.operationId)
40 if result.is_empty():
41 # Keep the file and original ID, including after timeout or OPERATION_EXPIRED.
42 push_error(Horizon.statistics.getLastErrorCode())
43 return
44 # A delayed O1 success cannot remove another action's O2 original.
45 if FileAccess.get_file_as_bytes(pending_path) == original_bytes:
46 DirAccess.remove_absolute(ProjectSettings.globalize_path(pending_path))
47 print(result.values)
测试你的新功能。
游戏在一个批次中上报完整会话,并显示当前计数器和周期。
在仪表盘中选择与游戏配置相同的项目。


