question

Justin Enayat avatar image
Justin Enayat asked

Getting Player Title Data with Leaderboards?

I have a key in the player data (title) called "Ships". I use this value to show which ship a user has equipped on their leaderboard entry. Only problem is, I don't know how to get this value to implement it into the leaderboard entry. I read about Player Profile Constraints, but I couldn't find a way to get player title data from it. Here's my leaderboard code:

    public void GetLeaderBoardTimeTrials()
    {
        var request = new GetLeaderboardRequest
        {
            StatisticName = (levelName),
            StartPosition = 0,
            MaxResultsCount = 100
        };
        PlayFabClientAPI.GetLeaderboard(request, OnLeaderboardTimeTrialsGet, OnError);
        noTimeText.SetActive(false);
    }


    void OnLeaderboardTimeTrialsGet(GetLeaderboardResult result)
    {
        foreach (Transform item in ttParent)
        {
            Destroy(item.gameObject);
        }
        foreach (var item in result.Leaderboard)
        {
            GameObject newGo = Instantiate(ttPrefab, ttParent);
            float timeConverter = item.StatValue;
            TimeSpan timeSpan = TimeSpan.FromSeconds(timeConverter / -100);
            string timeShow = timeSpan.ToString("mm':'ss'.'ff");
            TMP_Text[] texts = newGo.GetComponentsInChildren<TMP_Text>();
            texts[0].text = (item.Position + 1).ToString();
            texts[1].text = item.DisplayName;
            texts[2].text = timeShow;

	    //equippedShip = Player title data key value?


            string playerId = item.PlayFabId;



            var myFile = new EasyFile(myServerURL, $"{playerId}{load_levelID}.replay", "password");


            GameObject noData = newGo.transform.GetChild(3).gameObject;
            GameObject raceButton = newGo.transform.GetChild(4).gameObject;
            raceButton.GetComponent<Button>().onClick.AddListener(delegate 
            {
                Download(playerId, load_levelID); 
            } );
        }
    }
apisPlayer DataTitle DataLeaderboards and Statistics
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Gosen Gao avatar image
Gosen Gao answered

Calling GetUserData for each Leaderboard entry will increase the number of API calls (usually it is doubled). We have a limit that a client can request 100 times every 2 minutes. If you want to use the current solution, please make sure to page the list of leaderboard. In the common scenario, we suggest you to call GetUserData only when players click a leaderboard entry then show them the detailed info.

Also, you could set a number to each ship and create another Leaderboard like “Ships” to store player’s ship. When you want to get Leaderboard, you can add the parameter ProfileConstraints in the GetLeaderboard request body and set ShowStatistics to true, then it will return all the statistics of each player in Leaderboard you request now. But this is not a common scenario, and getting all Statistics of a player in the client may cause privacy issues. That’s why PlayFab doesn’t allow the client to read the Statistics in Profile by default. If you want to use this workaround, please navigate to [Game Manager]->[Title Setting]->[Client Profile Options]->[ALLOW CLIENT ACCESS TO PROFILE PROPERTIES]. And make sure the option “Statistics” is selected.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Justin Enayat avatar image Justin Enayat commented ·

I see, I might just do the first option where it only gets their data when they click

0 Likes 0 ·
Justin Enayat avatar image
Justin Enayat answered

Ok, so I'm trying to have the GetLeaderboard result also call a method to get the player title data. I think my problem is I don't know how to properly access the children of the instantiated gameobjects in ttParent. Basically, each ship is lined up unactivated in the instantiated gameobject, and the entries are just numbers that correspond to the order. I'm trying to make it so that the gameobject (an image) that corresponds with the player title data gets activated.

So in my OnLeaderboardGet I put these lines:

string playerId = item.PlayFabId;


GetOtherUserShipTTEntry(playerId);

Which calls this:

public void GetOtherUserShipTTEntry(string id)
    {
        PlayFabClientAPI.GetUserData(new GetUserDataRequest()
        {
            PlayFabId = id,
            Keys = null
        }, result =>
        {
            foreach (var item in result.Data)
            {
                int shipEntry = 0;
                if (result.Data != null)
                {
                    shipEntry = int.Parse(result.Data["Ship"].Value);
                }
                else
                {
                    shipEntry = 0;
                }
                SendOtherPlayersEquippedShip(shipEntry);
            }
        }, error => { });
    }

Which calls this:

    public void SendOtherPlayersEquippedShip(int entry)
    {
        foreach (var item in ttParent)
        {
            var ship = ttPrefab.transform;
             if (entry == null)
                entry = 0;
            GameObject shipChild = ship.GetChild(entry).gameObject;
            shipChild.SetActive(true);
        }
    }

Could really use some help :( lmk if anything needs clarifying

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.