Sign In Register

How can we help you today?

Start a new topic

Cloud code getRank() returns wrong value

 If I do this I can get the correct rank, but I guess is not the best for performance reasons: 

var entries = ldb.getEntries();
var rank = -1;
var score = -1;
while(entries.hasNext())
{
    var entry = entries.next();
    var entryId = entry.getAttribute("teamId")
    if(entryId == clanId)
    {
        rank = entry.getRank();
        score = entry.getAttribute("SUM-SCORE");            
        break;
     }
}
//rank is correct as well as score
        

 but if I do this:

 

var entries = ldb.getEntriesForItentifier(ID, {});
if(entries.length > 0)
{
     var rank = entries[0].getRank();        
     var score = entries[0].getAttribute("SCORE"));            
     //this score is correct but the rank is not
}

  or this:

 

 

I get the wrong rank, what am I doing wrong? or misunderstanding?


thanks in advance,

Chrys



Hi Chrystian,


What leaderboard is this in relation to ? If you can also let us know the player/team you are getting the rank for and the incorrect value you're receiving we can look into this some more for you.


Thanks,

Liam

Hi Liam,


This is happening with every leaderboard I tried, currently 12, 4 of them are team leaderboards and 8 are player leaderboards(but 4 are grouped by the team id the player belongs to as it serves as a team internal competition).


However I believe it is more related to the code or something I'm not understanding about how to use the SparkLeaderboards class.


I forgot to mention that this is my code to get the leaderboard in the cloud code:


var ldb = Spark.getLeaderboards().getLeaderboard(ldbShortCode);


Thanks, 

Chrys

Hi Chrystian,


Do you get the same erroneous rank when using ldb.getEntriesFromPlayer(ID, 1);?


Is the rank being returned consistent (e.g always 1) or relative to the players actual rank (e.g. rank +/- 1)?


What exactly are you trying to achieve here? If you are just trying to retrieve the player's position in the leaderboard it would probably be easier to use an AroundMeLeaderboardRequest from your client.


Regards,

Vinnie

Login to post a comment