Fetching Additional data in leaderbaord does not work

0 votes

Hi

I'm using Unity3D

I'm trying to save score with additional data using this method:

public void saveUserScore(string userName, int numLevel, double score, LeaderboardCallBack.LeaderboardDelegate callback){
     scoreBoardService = sp.BuildScoreBoardService(); 
     Dictionary<string, object> jsonDoc = new Dictionary<string, object> ();  
     jsonDoc.Add("level",("level"+numLevel.ToString())); 
     App42API.SetDbName(Constant_App42.dbName); 
     scoreBoardService.AddJSONObject(Constant_App42.collectionLeaderboards, jsonDoc);  
     scoreBoardService.SaveUserScore(Constant_App42.gameName, userName, score, callback); 
}

And then i'm trying to get user score from facebook using this method:

public void GetTopNRankersFromFacebook(int countRank, int numLevel, LeaderboardCallBack.LeaderboardDelegate callback){ 
    scoreBoardService = sp.BuildScoreBoardService(); 
    String key1 = "level";     
    String value1 = ("level" + numLevel.ToString ()); 
    Query query = QueryBuilder.Build(key1, value1, Operator.EQUALS); 
    App42API.SetDbName(Constant_App42.dbName);  
    scoreBoardService.SetQuery(Constant_App42.collectionLeaderboards, query); 
    App42Log.SetDebug(true);  
    leaderboardCallback.setLeaderboardCallback (callback);
    scoreBoardService.GetTopNRankersFromFacebook(Constant_App42.gameName, FB.AccessToken, countRank,       callback);    
}

For example, i save score to the app42 server:

name        score        additional info
                                     key        value
user1        200           level      level1
​user1        270           level      level1
​user2        350           level      level1
​user3        400           level      level2


I want to get 2 users with the highscore in level1 and i call my method GetTopNRankersFromFacebook(2, 1, callback)

i should get user2 with score 350 and user1 with score 270.

But i got user3 with score 400 from level2 and user2 with score 350 from level1. 

Why does it happen?

asked Jul 9, 2014 in AppWarp by alexander.bargamin (16 points)

1 Answer

0 votes

Hi Alexander,

You can achieve this by applying following steps in your app.

1.       Save the facebook profile of user in storage service.

2.       Save the score and additional info as you mentioned above.

3.       GetTopNTargetRankers method and pass the query for target users only. (In your case query would be level=level2) . This will generate the leaderboard for users who are in given level (level2)

4.       Now fetch facebook user profile of each user in the leaderboard from saved collection in step #1. This can be done for example using following query in Find Document By Query method

IList<String> docIds = new List<String>();

docIds.Add("user1");

docIds.Add("user2");

docIds.Add("user......");

Query myQuery  = QueryBuilder.Build("_id", docIds , Operator.INLIST); 

Let me know if you require further assistance regarding this.

Thanks

 

answered Jul 9, 2014 by hs00105 (517 points)
Maybe we did not understand each other. But my problem in 3rd step. If i want to get highscore for 2 users in 2nd level i pass the query in method GetTopNTargetRankers (level=level2) i get score 400 from level2 and user2 with score 350 from level1 instead only user3 with score 400 from level2. This method with this query does not generate the leaderboard for users who are in given level (level2). And i did not uderstand relation between 2nd and 3rd steps because the method GetTopNTargetRankers returns facebook user profile but with incorrect levels in my case.

I need further assistance regarding this. Please, send me a sample for getting score for example for level=level2 if you can.
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...