Game ideas & features

Your next feature

Player statistics

Track rounds, kills and best scores in one session batch, with sum, maximum, minimum or latest-value rules.

SDK developRequires a player session
Unity
Illustration of Player statistics
Your visible result

Your game reports one complete session batch and displays the current counters and periods.

Video coming later

This step does not have a video yet. The guide and MCP request are ready to use.

Player statistics

Prepare the same project

  1. Choose the same project in the dashboard as in your game configuration.

    Player statistics →
  2. Create or reuse these test entries in the dashboard form. These are example values, not current project data.

    Statistic definitions
    kills: mode=sum, reset=none; best_score: mode=max, reset=none

    Sum adds each report. Maximum and minimum keep the best value; latest replaces it. Maximum, minimum and latest initialize from the first report. Values are signed whole numbers within the safe-integer range.

  3. Save, reload and verify the entries before running the example. Preserve unrelated definitions.

Build this feature

You can preview the guide. Running it requires an active project key. Prepare project

SDK installed, project configuration imported and player signed in.

This SDK example uses develop. Check whether the required APIs exist in your installed SDK.

Complete the Quickstart connection with the intended player. Call RunReviewedAction() from an explicit button or scene action. Opening the file alone sends no request.

C#
Assets/Scripts/StatisticsDemo.cs
horizOn call
1using PM.horizOn.Cloud.Objects.Network.Requests;
2using UnityEngine;
3using PM.horizOn.Cloud.Core;
4using PM.horizOn.Cloud.Manager;
5​
6// Existing SDK/project configuration and authenticated player session required.
7// Call RunReviewedAction explicitly after reviewing this example and its data.
8// Read a snapshot first, then keep one operation ID and the original batch
9// through retries. An expired or uncertain result requires reconciliation,
10// never an automatic new-ID report.
11// This explicit action reports the shown persisted batch.
12public sealed class StatisticsDemo : MonoBehaviour
13{
14 public async void RunReviewedAction()
15 {
16 var sessionUser = UserManager.Instance.CurrentUser;
17 if (sessionUser == null || !sessionUser.IsValid()) return;
18 var manager = StatisticsManager.Instance;
19 var snapshot = await manager.GetStatistics();
20 if (snapshot == null) { Debug.LogWarning(manager.LastErrorCode); return; }
21 string pendingKey = "horizOn_statistics_pending_" + snapshot.userId;
22 var pending = PlayerPrefs.HasKey(pendingKey)
23 ? JsonUtility.FromJson<UpdateStatisticsRequest>(PlayerPrefs.GetString(pendingKey))
24 : new UpdateStatisticsRequest {
25 userId = snapshot.userId, operationId = manager.CreateOperationId(),
26 updates = new[] { new StatisticUpdate("kills", 3), new StatisticUpdate("best_score", 250) }
27 };
28 string originalJson = JsonUtility.ToJson(pending);
29 PlayerPrefs.SetString(pendingKey, originalJson);
30 PlayerPrefs.Save();
31 var result = await manager.UpdateStatistics(pending.updates, pending.operationId);
32 if (result == null) {
33 // Keep the saved ID and batch. Reconcile OPERATION_EXPIRED before a new logical report.
34 Debug.LogWarning(manager.LastErrorCode);
35 return;
36 }
37 // A late success for O1 must never acknowledge a newer pending O2.
38 if (PlayerPrefs.GetString(pendingKey, null) == originalJson) {
39 PlayerPrefs.DeleteKey(pendingKey);
40 PlayerPrefs.Save();
41 }
42 foreach (var counter in result.values) Debug.Log(counter.key + "=" + counter.value);
43 }
44}
Open the complete SDK sample ↗

Test your new feature.

Your game reports one complete session batch and displays the current counters and periods.

Choose the same project in the dashboard as in your game configuration.

Endpoints
  • GET/statistics
  • GET/statistics/definitions
  • POST/statistics
All endpoints in the API reference
Our suggestion for your next step

Give every round a high score.

Save the score after a round and show who's ahead. Keep using your connection and player session.