string[] leaderBoards = new string[1]{"highScoreLeaderboard"};
new GetLeaderboardEntriesRequest()
.SetLeaderboards(leaderBoards)
.Send((response) => {
var results = response.Results;
var scriptData = response.ScriptData;
// Not sure what to put here:
Debug.Log(scriptData.GetString("rank"));
});
Thank you,
Best Answer
L
Lawrence Abadier
said
over 7 years ago
Hi Beppi,
Sorry for the double post, thought I could edit. So I tested your snippet and keep getting the wrong rank. Here is what I used:
List<string> leaderboardCodes = new List<string>();
leaderboardCodes.Add("highScoreLeaderboard");
GetLeaderboardEntriesRequest leaderboard = new GetLeaderboardEntriesRequest();
leaderboard.SetLeaderboards(leaderboardCodes);
leaderboard.Send ((response) => {
if (!response.HasErrors) {
string json = response.JSONString;
var N = SimpleJSON.JSON.Parse(json);
var value = N["highScoreLeaderboard"]["rank"].AsInt;
Debug.Log("Player rank: " + value);
}
else
Debug.Log ("Get Player Score Leaderboard: FAIL with error " + response.Errors.JSON);
});
Hi, The request will work fine as long
as the current authenticated user has an entry in the leaderboard, if
they don't it will return null.
In the test harness when you authenticate the user, the player details including the user id will show in the inspector.
You can check in noSQL if the user is in the leaderboard.
Select highScoreLeaderboard as the collection
In query put {"userId" : "the id you got from the test harness goes here"}
If the player has a score in the leaderboard then it will show up in the results.
Thanks
Katie
B
Beppi Menozzi
said
over 7 years ago
Personally I couldn't get anything from response.Result, while instead I managed to receive the information I needed using JSON:
GetLeaderboardEntriesRequest leaderboard = new GetLeaderboardEntriesRequest();
leaderboard.SetLeaderboards(shortCodes);
leaderboard.Send ((response) => {
if (!response.HasErrors) {
string json = response.JSONString;
var N = SimpleJSON.JSON.Parse(json);
value = N["PScoreLeaderboard"]["S"].AsInt;
}
else
Debug.Log ("Get Player Score Leaderboard: FAIL with error " + response.Errors.JSON);
L
Lawrence Abadier
said
over 7 years ago
Hey Beppi, I will test your snippet (have to dl simplejson etc). In the meantime what is the PScoreLeaderboard and "S"? .
* So I looked in my NoSQL and the player is in fact in the leader boards. 1. I got the ID from NoSQL 2. Facebook authenticated 3. TestHarness GetLeaderboardEntriesRequest with the new ID 4. Get NotAuthorized , NULL. 5. Is my syntax correct for the C# snippet?
Thank you,
L
Lawrence Abadier
said
over 7 years ago
Answer
Hi Beppi,
Sorry for the double post, thought I could edit. So I tested your snippet and keep getting the wrong rank. Here is what I used:
List<string> leaderboardCodes = new List<string>();
leaderboardCodes.Add("highScoreLeaderboard");
GetLeaderboardEntriesRequest leaderboard = new GetLeaderboardEntriesRequest();
leaderboard.SetLeaderboards(leaderboardCodes);
leaderboard.Send ((response) => {
if (!response.HasErrors) {
string json = response.JSONString;
var N = SimpleJSON.JSON.Parse(json);
var value = N["highScoreLeaderboard"]["rank"].AsInt;
Debug.Log("Player rank: " + value);
}
else
Debug.Log ("Get Player Score Leaderboard: FAIL with error " + response.Errors.JSON);
});
B
Beppi Menozzi
said
over 7 years ago
It seems equal to mine, that appearantly works, at this point I think that it's better if I leave the solution to the customer service who might look if there is something wrong in the leaderboard config...
I also find odd that is necessary to pass through a json object instead of getting the value directly, but what is important is to get the work done :)
B
Beppi Menozzi
said
over 7 years ago
BTW, did you authenticate before the request?
L
Lawrence Abadier
said
over 7 years ago
Yes, I authenticate via device and facebook, both of which work and retrieve the correct leaderboard data.
L
Lawrence Abadier
said
over 7 years ago
I would appreciate if customer service could help me out with this issue, The game launch is being stalled because of it.
Customer Support
said
over 7 years ago
Hi Lawrence It seems like Facebook authenticated is not working for you. In the Test Harness when you run GetLeaderboardEntriesRequest you have to be authenticated. In the connection box the authToken has to be filled in. Run a FacebookConnectRequest in the test Harness with your accessToken
Once you are authenticated you will be able to run requests. Thanks Katie
L
Lawrence Abadier
said
over 7 years ago
Hi Katie,
Like I previously mentioned, I am fully authenticated, yet I cant make this request. This is my entire issue, is that I'm in-fact authenticated but the request returns NULL.
Thank you,
Customer Support
said
over 7 years ago
Hi Lawrence Including the userId in the Player Field in the Test Harness will give you the leaderboard entries.
So I finally got it to work with the ID, but according
to the documentation if left blank it should use the current ID. How do I
go about doing this in C# for unity? I have the following:
public void GetPlayerRank(){
List<string> leaderboardCodes = new List<string>();
leaderboardCodes.Add("highScoreLeaderboard");
new GetLeaderboardEntriesRequest()
.SetLeaderboards(leaderboardCodes)
.SetPlayer(AccessToken.CurrentAccessToken.UserId)
.Send((response) => {
if(response.HasErrors)
{
playerRank.text = "ERROR!";
Debug.LogError("Couldnt get player rank for some reason");
}else{
var results = response.Results;
var scriptData = response.ScriptData;
// Not sure what to put here:
playerRank.text = "RANK: " + results.GetString("rank");
Debug.Log("RANK Result: " + results.GetString("rank"));
Debug.Log("RANK Script: " + scriptData.GetString("rank"));
}
});
}
Is this the correct way to get the ID in code? because its returning nothing so far =/ . Under the test harness it is working though.
Customer Support
said
over 7 years ago
Hi Lawrence
When you call a FacebookConnectRequest you are returned the user Id in the response
I'm sorry to be a pain but I have read the documentation and as you can see from my first post I have what is in the documentation. The issue is that I do not know what to do with the GSDATA scriptData in code, and nothing in the documentation tells me what to do with it.
My question is simple, and I need help with it in the code it self.
Given a leaderboard short code named: "highScoreLeaderBoard" And ID "56103bc5dd3049eb" (example id) how do I get the rank in c#? The test harness still returns scriptData as null ( it even returns null in code). This is what i see in the test harness:
public void GetPlayerRank(){
List<string> leaderboardCodes = new List<string>();
leaderboardCodes.Add("highScoreLeaderboard");
new GetLeaderboardEntriesRequest()
.SetLeaderboards(leaderboardCodes)
.SetPlayer("56103bc5dd3049eb")
.Send((response) => {
if(response.HasErrors)
{
Debug.LogError("Couldnt get player rank for some reason");
}else{
var results = response.Results;
var scriptData = response.ScriptData;
if(scriptData != null){ // ALWAYS NULL
int rank = int.Parse(scriptData.GetString("rank"));
Debug.Log("Rank is: " + rank);
}
// Not sure what to put here:
}
});
}
Feel free to look under my account to see this for your self. I have been stuck on this for too long and would appreciate it, if someone could help me with the c# portion. I even tried messing around with the rest of the data under response, but couldnt come up with the rank.
Lawrence Abadier
Hi,
So I have a leaderboard with the short code: highScoreLeaderboard and I want to get the current player's rank.
According to the documentation if I leave "player" empty, then it uses the current player, but It always returns null.
Under test harness I tried the following but always returns null:
And in code I tried the following:
Thank you,
Sorry for the double post, thought I could edit. So I tested your snippet and keep getting the wrong rank. Here is what I used:
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstCustomer Support
Hi,
The request will work fine as long as the current authenticated user has an entry in the leaderboard, if they don't it will return null.
In the test harness when you authenticate the user, the player details including the user id will show in the inspector.
You can check in noSQL if the user is in the leaderboard.
Select highScoreLeaderboard as the collection
In query put {"userId" : "the id you got from the test harness goes here"}
If the player has a score in the leaderboard then it will show up in the results.
Thanks
Katie
Beppi Menozzi
Personally I couldn't get anything from response.Result, while instead I managed to receive the information I needed using JSON:
Lawrence Abadier
I will test your snippet (have to dl simplejson etc). In the meantime what is the PScoreLeaderboard and "S"? .
* So I looked in my NoSQL and the player is in fact in the leader boards.
1. I got the ID from NoSQL
2. Facebook authenticated
3. TestHarness GetLeaderboardEntriesRequest with the new ID
4. Get NotAuthorized , NULL.
5. Is my syntax correct for the C# snippet?
Thank you,
Lawrence Abadier
Sorry for the double post, thought I could edit. So I tested your snippet and keep getting the wrong rank. Here is what I used:
Beppi Menozzi
It seems equal to mine, that appearantly works, at this point I think that it's better if I leave the solution to the customer service who might look if there is something wrong in the leaderboard config...
I also find odd that is necessary to pass through a json object instead of getting the value directly, but what is important is to get the work done :)
Beppi Menozzi
BTW, did you authenticate before the request?
Lawrence Abadier
Lawrence Abadier
Customer Support
It seems like Facebook authenticated is not working for you.
In the Test Harness when you run GetLeaderboardEntriesRequest you have to be authenticated.
In the connection box the authToken has to be filled in.
Run a FacebookConnectRequest in the test Harness with your accessToken
{
"@class": ".FacebookConnectRequest",
"accessToken": "",
"code": "",
"doNotLinkToCurrentPlayer": false,
"errorOnSwitch": false,
"segments": {},
"switchIfPossible": false,
"syncDisplayName": false
}
Once you are authenticated you will be able to run requests.
Thanks
Katie
Lawrence Abadier
Like I previously mentioned, I am fully authenticated, yet I cant make this request. This is my entire issue, is that I'm in-fact authenticated but the request returns NULL.
Thank you,
Customer Support
Including the userId in the Player Field in the Test Harness will give you the leaderboard entries.
{
"@class": ".GetLeaderboardEntriesRequest",
"leaderboards": [
"highScoreLeaderboard"
],
"player": "player userId here"
}
Thanks
Katie
Lawrence Abadier
Hi Katie,
So I finally got it to work with the ID, but according to the documentation if left blank it should use the current ID. How do I go about doing this in C# for unity? I have the following:
Is this the correct way to get the ID in code? because its returning nothing so far =/ . Under the test harness it is working though.
Customer Support
Hi Lawrence
When you call a FacebookConnectRequest you are returned the user Id in the response
or you use AccountDetailsRequest
To get an leaderboard entry
Rank can be accessed by scriptData
You can find the c# client api documents here
Thanks
Katie
Lawrence Abadier
I'm sorry to be a pain but I have read the documentation and as you can see from my first post I have what is in the documentation. The issue is that I do not know what to do with the GSDATA scriptData in code, and nothing in the documentation tells me what to do with it.
My question is simple, and I need help with it in the code it self.
Given a leaderboard short code named: "highScoreLeaderBoard"
And ID "56103bc5dd3049eb" (example id)
how do I get the rank in c#? The test harness still returns scriptData as null ( it even returns null in code). This is what i see in the test harness:
as you can see the scriptData is in fact null.
And here is my c# code:
Feel free to look under my account to see this for your self. I have been stuck on this for too long and would appreciate it, if someone could help me with the c# portion. I even tried messing around with the rest of the data under response, but couldnt come up with the rank.
Thank you,
-
Documentation Notes
-
Design issues with user events
-
Using NoSQL
-
Runtime Collections vs Metadata Collections
-
Anonymous authentication from browser app
-
Modules
-
Movement With Unity
-
Problem with url parameters for downloadables
-
Querying NoSql GameSparks database
-
Challenge accesType
See all 2487 topics