Skip to main content

Get Scores By User ID

To get scores by user/player using the Leaderboard-Unity-SDK, follow the steps below.

Step 1: Initialize the Leaderboard Manager

1. Using Environment Variables

Automatically initialize MyriaLeaderboardSDKManager using environment variables.

Once all the required parameters are provided in the MyriaLeaderboardConfig object in the inspector, the MyriaLeaderboardSDKManager will automatically initialize based on the environment variables.

Import sample:

unity-install-step-10

2. Using the Init Function in Unity

To initialize the MyriaLeaderboardSDKManager, simply call the MyriaLeaderboardSDKManager.Init function in Unity. This will set up the SDK with the required configurations.

Sample code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MyriaLeaderboard;
using MyriaLeaderboard.Requests;
using System;

public class GamẹObjectTest : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{

MyriaLeaderboardSDKManager.Init("developerApiKey",
"publicRSAKey",
MyriaLeaderboard.MyriaLeaderboardEnums.MyriaEnvironment.Staging,
"1.0.0",
"https://game-server-url.com",
MyriaLeaderboardConfig.DebugLevel.All
);
}
}

MyriaLeaderboardSDKManager.Init(...) Parameters:

  • developerApiKey (string): The Developer API key provided by Myria Admin, required for authentication.
  • publicRSAKey (string): The RSA public key generated by your local server, used for encryption.
  • env (enum): Specify the environment for testing using the MyriaLeaderboard.MyriaLeaderboardEnums.MyriaEnvironmentenum. Recommend using Staging for Test environment and Prod for Live environment.
  • version (string): The version of the SDK you wish to specify.
  • gameServerUrl (string): The URL of your game server, either generated by Myria's template or your existing server.
  • debugLevelMode (string): Sets the debug level mode to control log visibility for troubleshooting in your game.

Step 2: Define Retrieve Player Score Leaderboard Parameters

The score list for the specific player in the leaderboard is single object, so you’ll need to specify userId and leaderboardId to query the score for the specific players.

Method:

void Start()
{
MyriaLeaderboardSDKManager.GetUserScore("leaderboard_id", "user_id", (response) =>
{
Debug.Log(response.data.userId);
}, null);
}
  • leaderboardId (string): The unique identifier of the leaderboard to query all associated scores.
  • userId (string): The unique identifier of player in the leaderboard.

Step 3: Retrieve player's score in the Leaderboard

Once you have defined the parameters, you can get the list scores of leaderboards by calling the GetListLeaderboard method on the MyriaLeaderboardSDKManager instance.

Sample Code in Editor:

unity_sdk_get_player_score

Sample Code Scripts:

void Start()
{
MyriaLeaderboardSDKManager.GetUserScore("111", "12", (response) =>
{
Debug.Log(response.data.userId);
}, null);
}

Ouput Details:

The method returns an GetUserScoreResponse object that contains detailed information about the user's score and the associated leaderboard.

  • score (number): The user's score in the leaderboard.
  • leaderboardId (number): The ID of the leaderboard.
  • userId (string): The ID of the user.
  • ranking (number): The rank of user in the current leaderboard.
  • period (number, optional): The period in which the score was recorded.
  • leaderboard (LeaderboardInfo): Detailed information about the leaderboard.
  • user (User): Detailed information about the user.

Leaderboard Data Object (LeaderboardInfo)

  • name (string): The name of the leaderboard.
  • description (string): A description of the leaderboard.
  • updateScoreStrategy (string): The strategy used to update scores (e.g., OVERWRITE, ACCUMULATE).
  • gameName (string): The name of the game associated with the leaderboard.
  • totalPeriods (number, optional): The total number of periods in the leaderboard.
  • livePeriodInDays (number): The number of days the leaderboard is live.
  • availableAt (string): The timestamp when the leaderboard is available.
  • enableMetadata (boolean, optional): Indicates whether metadata is enabled for the leaderboard.
  • developerId (string, optional): The ID of the developer who created the leaderboard.
  • status (string): The current status of the leaderboard (e.g., ACTIVE, INACTIVE).
  • currentPeriod (number): The current period of the leaderboard.
  • dataPersistenceInDays (number): The number of days the leaderboard data is persisted.
  • expireAt (string): The timestamp when the leaderboard will expire.
  • updatedAt (string, optional): The timestamp when the leaderboard was last updated.
  • createdAt (string, optional): The timestamp when the leaderboard was created.
  • id (number): The unique ID of the leaderboard.
  • enablePeriodRefresh (boolean, optional): Indicates whether period refresh is enabled for the leaderboard.

Summary

By following these steps, you can successfully get a score by players on a leaderboard using the Leaderboard-Unity-SDK. This process involves initializing the LeaderboardManager, defining the score parameters, and invoking the postScore method to submit the score.

For more details on the available options and additional features, refer to the full documentation.