Sign In Register

How can we help you today?

Start a new topic

Retrieving rank data from LeaderboardsEntriesRequest

Hi everybody,

What is the way you retrieve the rank for the current player for a leaderboard? I've tried a lot of methods but none of the below work... Using Unity 2017.3 and C#

List<string> lbShortCode = new List<string>();
	lbShortCode.Add(stage.LeaderboardShortCode);

	new LeaderboardsEntriesRequest().
	SetLeaderboards(lbShortCode).
	Send((response) =>
	{
		if (!response.HasErrors)
		{

			Debug.Log(response.JSONString); // contains the information I need
			Debug.Log(response.Results.GetGSData(lbShortCode[0]).GetNumber("rank").GetValueOrDefault()); // null
			Debug.Log(response.ScriptData.GetGSData(lbShortCode[0]).GetNumber("rank").GetValueOrDefault()); // null
			Debug.Log(response.BaseData.GetGSData(lbShortCode[0]).GetNumber("rank").GetValueOrDefault()); // null
		}
	}

  The JSONData contains the information I want. Is the only way via a JSON parser? If so, then why are all these other options even available? One would just expect the Results object to contain the results... Why is such a trivial task so hard? From what I could find in the docs it says the rank should be in ScriptData, but nope, doesn't work.

Don't get me wrong, I love the functionality GameSparks gives me, but so many features seem cluttered with stuff that doesn't do anything, or features that are poorly documented. 


Maybe I'm missing something basic about how the SDK works, any help is appreciated.

Regards,
Bart


2 people have this question

Ok, so I figured something out.

I was using LeaderBoardEntriesRequest instead of GetLeaderBoardEntriesRequest.

Both returned ALMOST exactly the same JSON:

 

LeaderboardEntriesRequest:
{"@class":".LeaderboardsEntriesResponse","requestId":"636548005533735780_6","STAGES.HASH.EDQBESOLEVONKZ":[{"userId":"5a8c273b6d5542d6fc9e424b","VALUE":21300,"HASH":"EDQBESOLEVONKZ","REPLAY":"","when":"2018-02-21T08:02Z","city":"'s-hertogenbosch","country":"NL","userName":"fdgfdgfdgdf!0","externalIds":{},"rank":5}]}

GetLeaderboardEntriesRequest:
{"@class":".GetLeaderboardEntriesResponse","requestId":"636548005533729480_5","STAGES.HASH.EDQBESOLEVONKZ":{"userId":"5a8c273b6d5542d6fc9e424b","VALUE":21300,"HASH":"EDQBESOLEVONKZ","REPLAY":"","when":"2018-02-21T08:02Z","city":"'s-hertogenbosch","country":"NL","userName":"fdgfdgfdgdf!0","externalIds":{},"rank":5}}

 As you can see, the only difference being LeaderBoardsEntriesRequest has [ ] enclosing the values.

So I got it working now... but my question is. Why (!) does LeaderBoardsEntriesRequest exist?! It has gotten me confused for 2 days.

Bart,


I've been stuck with the same thing. I can see the rank in the console log, but I am stumped as to how to get the actual int from that data. Can you tell me how?


Thanks

John

Login to post a comment