Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • General Discussion /
avatar image
Question by Justin Enayat · Oct 13, 2021 at 07:00 PM · apisPlayer DataLeaderboards and StatisticsTitle Data

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); 
            } );
        }
    }
Comment

People who like this

0 Show 0
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Gosen Gao · Oct 14, 2021 at 03:37 AM

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.

Comment
Justin Enayat

People who like this

1 Show 1 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Justin Enayat · Oct 14, 2021 at 04:18 AM 0
Share

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

avatar image

Answer by Justin Enayat · Oct 14, 2021 at 02:29 AM

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

Comment

People who like this

0 Show 0 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    8 People are following this question.

    avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

    Related Questions

    Updating Online / Offline status of player? 1 Answer

    GetUserData vs GetPlayerProfile ? why Different 1 Answer

    Recommended Method for Cost-Based Player Display Name Changes? 1 Answer

    Admin panel in unity, to modify the statistics of the player you want / choose,Modify player data in a unit panel 1 Answer

    Is it possible to get the sum value of a player statistic, eg total number of kills for all players 1 Answer

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges