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

Login to post a comment