question

Silvercaster893 avatar image
Silvercaster893 asked

Get All Scores For A Leaderboard

Hello! I'm using the GameCircle 2.x plugin for Unity, and I'm trying to retrieve the top 100 scores from a leaderboard for use in a custom UI for a leaderboard in my game. I have been able to successfully retrieve the AGSLeaderboard object I want, however, whenever I call its scores property (which is supposed to be a List of AGSScores), it comes back with a count of 0. I've gone to the default leaderboard overlay and I can see the score there (I only have one score there so far), so I know the leaderboard has the score, but I can't seem to get a reference to it in code. Is there something else I need to do, or is this a bug with the Unity code?
10 |5000

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

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi Silvercaster, Cant we add following methods in AGSLeaderboardsClient to get the top scores like java. public static void getScores( string leaderboardId, LeaderboardFilter filter ){ JavaObject.Call( "getScores", leaderboardId, filter); } public static void GetScoresFailed( string json ){ } public static void GetScoresSucceeded( string json ){ } Have you tried with this already?
10 |5000

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

sg-justin avatar image
sg-justin answered
I have the same problem using Unity SDK on iOS. RequestLeaderboardsSucceeded is called and the json returned is an array like this [{"name":"","id":"","scoreFormat":"NUMERIC","displayText":"Points"}]. No scores. I need to be able to grab top n scores. I can try the java call for Android but for iOS this is all in the library?
10 |5000

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

sg-justin avatar image
sg-justin answered
I tried calling "getScores" in java. Exception: java.lang.NoSuchMethodError: no method with name='getScores' signature='(Ljava/lang/String;Ljava/lang/String;)V' in class Lcom/amazon/ags/api/unity/LeaderboardsClientProxyImpl;
10 |5000

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

Silvercaster893 avatar image
Silvercaster893 answered
Sorry for abandoning this topic for so long.. Things came up at work that forced me to abandon this project for a while. But I'm working on it again now, and have some more insight. Following the lead of the posts above, I found that the method we were looking for DOES exist - it's just called "requestScores" instead of "getScores" So far I've managed to make a call to it and have success and fail events for it; I even have it returning the json list of scores properly. Where I'm having trouble now is getting it to translate the json into a list of AGSScores. I'll post the code I've done so far, to hopefully help out other developers, but bare in mind that I've commented out everything regarding iOS, as I don't need it for my project, and it was causing compile errors when I left it in, so I haven't done any sort of testing on iOS for this at all. Add to AGSLeaderboardClient.cs: Add to the list of iOS function declarations: (UNTESTED!!) [DllImport ("__Internal")] private static extern void _AmazonGameCircleRequestScores( string leaderboardId, int scope, int startRank, int count); Add to the declaration of Actions: /// /// Event called when a score request fails /// /// the id of the leaderboard for the failed request /// a string indicating the failure reason public static event Action RequestScoresFailedEvent; /// /// Event called when a score request succeeds /// /// the id of the leaderboard for the score request /// list of scores returned public static event Action > RequestScoresSucceededEvent; Add below the RequestLocalPlayerScore method: (Obviously, uncomment the iOS line if you want to use that) /// /// request scores, starting at startRank, for a given leaderboard and scope /// /// /// RequestScoresSucceededEvent or RequestScoresFailedEvent events will be called if they are registered /// /// the id of the leaderboard for the score request /// enum value of leaderboard scope /// the rank to start counting from /// the number of scores to return public static void RequestScores( string leaderboardId, LeaderboardScope scope, int startRank, int count ){ #if UNITY_EDITOR && (UNITY_ANDROID || UNITY_IOS) // GameCircle only functions on device. #elif UNITY_ANDROID JavaObject.Call( "requestScores", leaderboardId, (int)scope, startRank, count ); #elif UNITY_IOS //_AmazonGameCircleRequestScores(leaderboardId, (int)scope); #else if( RequestScoresFailedEvent != null ){ RequestScoresFailedEvent( leaderboardId, "PLATFORM_NOT_SUPPORTED" ); } #endif } Add below the RequestLocalPlayerScoreSucceeded method: /// /// callback method for native code to communicate events back to unity /// public static void RequestScoresFailed( string json ){ if( RequestScoresFailedEvent != null ){ var ht = json.hashtableFromJson(); string leaderboardId = GetStringFromHashtable(ht,"leaderboardId"); string error = GetStringFromHashtable(ht,"error"); RequestScoresFailedEvent( error ); } } /// /// callback method for native code to communicate events back to unity /// public static void RequestScoresSucceeded( string json ) { if( RequestScoresSucceededEvent != null ) { Debug.Log("*******************************json = \n\n" + json + "\n\n*******************************"); var arrayList = json.arrayListFromJson(); List scores = new List (); if(arrayList != null) { Debug.Log("*******************************success! getting scores*******************************"); scores = AGSScore.fromArrayList(arrayList); Debug.Log("*******************************scores.count = " + scores.Count + "*******************************"); } else { Debug.Log("*******************************null list*******************************"); } RequestScoresSucceededEvent( scores ); } } Add to GameCircleManager: Add below RequestLocalPlayerScoreSucceeded: public void requestScoresFailed( string json ) { AGSClient.Log ("GameCircleManager - requestScoresFailed"); AGSLeaderboardsClient. RequestScoresFailed( json ); } public void requestScoresSucceeded( string json ) { AGSClient.Log ("GameCircleManager - requestScoresSucceeded"); AGSLeaderboardsClient. RequestScoresSucceeded(json); } The RequestScoresSucceeded method, in AGSLeaderboardClient, is where I'm having the trouble, as you can see by my log statements; the json is printing out correctly, but when I try turning it into an arrayList, it returns null.. Does anyone have any thoughts on why that might be?
10 |5000

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

khardey avatar image
khardey answered
For anyone else looking for an answer, I followed Silvercaster893's advice above. The RequestScoresSucceeded method that worked for me is below. First you need the json converted to a hashtable, then the arraylist of hashtable scores. public static void RequestScoresSucceeded( string json ){ if( RequestScoresSucceededEvent != null ){ List scores = new List (); Hashtable ht = json.hashtableFromJson(); if(ht.ContainsKey("scores")){ ArrayList scoresArray = (ArrayList)ht["scores"]; for(int j = 0; j < scoresArray.Count; j++){ scores.Add(AGSScore.fromHashtable((Hashtable)scoresArray[j])); } } RequestScoresSucceededEvent(scores); } }
10 |5000

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