Sign In Register

How can we help you today?

Start a new topic
Answered

How to get the score for the current user (unity)

Hello, I'm not a programmer but I try.

As I can get the score of the current user?


could give me some example ?,


thank you very much


Best Answer

solved, using 

int score = (int)response2.BaseData.GetGSData("friendsHighScore").GetNumber("score"); 

  instead of


string score = response2.JSONData["score"].ToString();

 for if it helps someone


this is my code... 

 

	public void GetScore()
	{
		Debug.Log ("Obteniendo el Score!");
		new AccountDetailsRequest ()
			.Send ((response) => {
			if (!response.HasErrors) {
				string PlayerID = response.UserId;
					Debug.Log ("Se encontro el ID del jugador:" + PlayerID);
					new GetLeaderboardEntriesRequest ().SetPlayer (PlayerID).SetLeaderboards(leadboard).Send ((response2) => {
					string score = response2.JSONData["score"].ToString();
					LoggedUI.transform.FindChild("FBScore").GetComponent<Text>().text = score;
				});
			}

		});

 

error output:

 

KeyNotFoundException: The given key was not present in the dictionary.
System.Collections.Generic.Dictionary`2[System.String,System.Object].get_Item (System.String key) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:150)
LoginFacebook.<GetScore>m__4 (GameSparks.Api.Responses.GetLeaderboardEntriesResponse response2) (at Assets/00 LAFAR/03 Scripts/Social/LoginFacebook.cs:156)
GameSparks.Core.GSTypedRequest`2+<>c__DisplayClass1[GameSparks.Api.Requests.GetLeaderboardEntriesRequest,GameSparks.Api.Responses.GetLeaderboardEntriesResponse].<Send>b__0 (GameSparks.Core.GSObject response)
GameSparks.Core.GSRequest+<>c__DisplayClass4.<Complete>b__1 ()
GameSparks.Platforms.PlatformBase.Update () (at Assets/GameSparks/Platforms/PlatformBase.cs:67)

 

Answer

solved, using 

int score = (int)response2.BaseData.GetGSData("friendsHighScore").GetNumber("score"); 

  instead of


string score = response2.JSONData["score"].ToString();

 for if it helps someone


1 person likes this

Nice work Gerick.


Glad you figured it out.


Oisin

I've tried to do this but just get a cast error whenever I try to get the current player's leaderboard rank. I'm using a partitioned leaderboard btw. 


using:

if (response.BaseData.GetGSData("weeklymultiplayer").ContainsKey("rank"))


also tried

 if (response.BaseData.GetGSData("weeklymultiplayer.game.mygamename").ContainsKey("rank"))


also tried:

if(response.ScriptData.ContainsKey("rank") )


Why is there no documentation for how to retrieve the player's leaderboard entry?

 at GameSparks.Core.GSTypedRequest`2+<>c__DisplayClass1[GameSparks.Api.Requests.GetLeaderboardEntriesRequest,GameSparks.Api.Responses.GetLeaderboardEntriesResponse].<Send>b__0 (GameSparks.Core.GSObject response) [0x00008] in c:\jenkins\workspace\clientsdk-dotnet-rt-tls\GameSparks.Api\Core\GSTypedRequest.cs:118 
  at GameSparks.Core.GSRequest+<>c__DisplayClass4.<Complete>b__1 () [0x00000] in c:\jenkins\workspace\clientsdk-dotnet-rt-tls\GameSparks.Api\Core\GSRequest.cs:78 
  at GameSparks.Platforms.PlatformBase.Update () [0x0007d] in Assets\GameSparks\Platforms\PlatformBase.cs:290 
UnityEngine.Debug:Log(Object)
GameSparks.Platforms.PlatformBase:Update() (at Assets/GameSparks/Platforms/PlatformBase.cs:295)

 

I think it's not working because the returned leaderboard name has a bunch of extra stuff in it like SNAPSHOT and a date.. so the GetGSData(..) call always returns null as it can't find a key with the actual leaderboard name. How do we get around this?

Login to post a comment