question

lifebeltgames avatar image
lifebeltgames asked

GetUserData from Leaderboard

Hi,

I have seen on some posts that we can not automatically reach userdata from getleaderboard method. We can reach each playerid and we can getuserdata for that id. But also you have mentioned querying through a list of let's say 30 people userdata is against your policy.

- Am I missing something on those statements or is there a way to capture userdata from leaderboard request?

- If not, is there any update adding it to your feature list and when would it be if there is? My company insists on featuring some extra userdata on leaderboard and actually it is a crucial feature. If it is a close plan, I can ask them to implement the feature later when it is available.

- In the case we cannot reach it, is there any workaround to get userdata from leaderboard elements? I have even thought serializing displayname with the necessary data but then we check if the displayname is unique to each client.

Thanks

Leaderboards 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.

brendan avatar image
brendan answered

Since we have a wide range of functionality, it's best to start from a top-down perspective when investigating how to implement a feature. So, rather than choosing a specific implementation, let us know what the goal of the design is, and we can give you the best approach.

In this case, your goal is to present some extra data with each leaderboard entry. You are correct that getting a leaderboard, then calling an API method for every player in the leaderboard is not going to work, as it would generate an excessive number of calls to the service, causing throttling on the title.

With each leaderboard entry, we provide the option to return any or all of the components of the player profile (https://api.playfab.com/documentation/Client/datatype/PlayFab.Client.Models/PlayFab.Client.Models.PlayerProfileViewConstraints). So for example, if the extra data you want returned is numeric, consider making it a statistic. If it's a string value, consider making it a Tag. Other elements, like AvatarUrl and user geolocation are provided directly, so you wouldn't need to create a Tag for those specifically.

What are the specifics of the extra data your title wants to display?

4 comments
10 |1200

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

lifebeltgames avatar image lifebeltgames commented ·

Hi Brendan,

Thanks for your answer. The data I want to display is a simple integer of the players emblem id.

So you are suggesting for me to save my userdata(emblem id) as statistic and while getting score leaderboard, i should simply request.ProfileConstraints.ShowStatistics = true; to get extra data(emblem id) from the player profile in leaderboard. I have created an emblem id leaderboard already and used the method above. Unfortunately such request causes nullreferenceexception in Unity log.

Am I doing something wrong?

0 Likes 0 ·
brendan avatar image brendan lifebeltgames commented ·

What request specifically? If it's the call to get the leaderboard, can you provide the code snippet? If the emblem ID is built in some complex manner (if the player can build their emblem from a range of parts, and the ID is really just a bitfield containing all that info), you should store it as a statistic. Otherwise, it could be a statistic or a tag, since there there won't be thousands of different ones.

For reading it from the leaderboard, bear in mind that the statistics are numeric, while Tags are strings.

0 Likes 0 ·
lifebeltgames avatar image lifebeltgames commented ·

I am posting the related C# code :

PlayFab.ClientModels.GetLeaderboardRequest request = new PlayFab.ClientModels.GetLeaderboardRequest ();
        request.MaxResultsCount = 30;
        request.StatisticName = "Score";
        request.ProfileConstraints.ShowStatistics = true;
        PlayFabClientAPI.GetLeaderboard (request, ongetleaderboard, ongetleaderboarderror);

The request.ProfileConstraints.ShowStatistics = true; part is giving null reference exception. From what I want to do is; I want to reach the statistic of emblem id registered for obtained players. Normally emblem id was registered as userdata but after your suggestion I have registered it as statistic but now, I encounter that nullreferenceerror.

Can you guide me what is causing this error?

Thanks

0 Likes 0 ·
brendan avatar image brendan lifebeltgames commented ·

Can you please provide the Title ID and the complete body of the response to the GetLeaderboard call above, showing the error message?

0 Likes 0 ·
lifebeltgames avatar image
lifebeltgames answered

Surely,

My title id is : 384D

Sdk version is : 2.23.170612

The error is :

NullReferenceException: Object reference not set to an instance of an object playfabmanager.getleaderboard () (at Assets/Menu items/Menu code/playfabmanager.cs:222) menuranking.registerranking () (at Assets/Menu items/Menu code/menuranking.cs:42) playfabmanager.onlogin (PlayFab.ClientModels.LoginResult result) (at Assets/Menu items/Menu code/playfabmanager.cs:73) PlayFab.Internal.PlayFabHttp+<MakeApiCall>c__AnonStorey0`1[PlayFab.ClientModels.LoginResult].<>m__1 () (at Assets/PlayFabSdk/Shared/Internal/PlayFabHttp/PlayFabHTTP.cs:176) PlayFab.Internal.PlayFabWww+<MakeApiCall>c__AnonStorey1.<>m__0 (System.String response) (at Assets/PlayFabSdk/Shared/Internal/PlayFabHttp/PlayFabWWW.cs:102) UnityEngine.Debug:LogException(Exception) PlayFab.Internal.<MakeApiCall>c__AnonStorey1:<>m__0(String) (at Assets/PlayFabSdk/Shared/Internal/PlayFabHttp/PlayFabWWW.cs:106) PlayFab.Internal.<Post>c__Iterator0:MoveNext() (at Assets/PlayFabSdk/Shared/Internal/PlayFabHttp/PlayFabWWW.cs:176) UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

The error line comes from this exact line :

request.ProfileConstraints.ShowStatistics = true;
5 comments
10 |1200

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

brendan avatar image brendan commented ·

So, the null reference exception is coming from line 222 in your playfabmanager.cs code - can you please provide the code snippet showing what all it does around that point in the code?

0 Likes 0 ·
lifebeltgames avatar image lifebeltgames commented ·

Hi Brendan,

It has nothing to do with any of menuranking code or line 73. They are just calls to each other or the method in the image. This is definitely about a wrong behaviour in PlayFab.ClientModels.GetLeaderboardRequest in my opinion if the use in the image is correct.

0 Likes 0 ·
brendan avatar image brendan lifebeltgames commented ·

I'm not sure where line 73 comes from, there - the top of the callstack you sent specifies:

NullReferenceException: Object reference not set to an instance of an object playfabmanager.getleaderboard () (at Assets/Menu items/Menu code/playfabmanager.cs:222)

That's why I'm asking if you could post all the related code, so thanks for providing the full listing, for context. The problem is that you haven't instantiated ProfileConstraints, which you need to do before using it. So if you add this just above where you want to set ShowStatistics to true, you should be fine:

request.ProfileConstraints = new PlayerProfileViewConstraints();
0 Likes 0 ·
lifebeltgames avatar image lifebeltgames commented ·

Hi Brendan,

Thank you very much for your answer. It still did not work in Client API, returned with invalid parameter but I managed to get it with Server API. I believe using Server API for it in client is not a problem.

Have a nice day

0 Likes 0 ·
brendan avatar image brendan lifebeltgames commented ·

What does the rest of the error response say? When you get the invalid parameters error, the errorDetails will always contain specific information on which parameter is missing or otherwise invalid.

0 Likes 0 ·

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.