Sign In Register

How can we help you today?

Start a new topic

Problem posting score to partitioned leaderboard


I'm having a problem with posting a score of a player to a partitioned leaderboard.

I have partitioned the leaderboard with an attribute called 'STAGE'. When the player completes a level, the score get's posted to GameSparks. It could be that this stage is a custom stage and so there is no leaderboard partition yet. I found the partition gets created automatically so this shouldn't be a problem.

It all seems te work. Except... when the leaderboard does not exist yet, the score sometimes gets posted, and sometimes it does not. I have some cloud code attatched to the Score event that credits the player with a currency and sends a manual message if they have beaten their old score. I use a manual high score because the there are some other attributes associated with my leaderboard could get updated and trigger a regular highscoremessage, which I do not want.

However, I don't think this is the problem but for completions sake here's the code:


var newScore = Spark.getData().VALUE;
if (newScore===null)

var leaderBoardShortCode = "STAGES.STAGE." + Spark.getData().STAGE;

//get the entry from last weeks leaderboard
var leaderBoard = Spark.getLeaderboards().getLeaderboard(leaderBoardShortCode);
var entry = null;

if (leaderBoard !== null)
    entry = leaderBoard.getEntriesFromPlayer(Spark.getPlayer().getPlayerId(), 1).next();

//get the score from last weeks entry
var oldScore = 0;
if (entry !== null)
    oldScore = entry.getAttribute("VALUE");

//compare them
if(newScore >= oldScore){
    // update total XP
    var player = Spark.getPlayer();
    //player.addVGood("XP", (newScore-oldScore));
    player.credit1(newScore-oldScore, "Level high score")
    // custom high score message, can't use the standard one
    // because the LEVEL (last) value updates on all the leaderboard partitions
    var highscoreMessage = Spark.message("HIGHSCORE");
    highscoreMessage.setMessageData({"LeaderBoardShortCode" : leaderBoardShortCode});


For testing purposes I am deleting all the entries via the Manage leaderboard tool and trying from the test harness and in my unity game. Both give me the same result.. sometimes the score is logged, and sometimes it is not. (I am removing the entries AND the running totals).

My manual highscore message does get delivered though... 

Hope someone can chime in. Thanks.



Hi Bart

Can you give me the steps to recreate this in the test harness?



Hi Katie,

Yes. First I authenticate with a user.... then log a 'Score' event, like this:


  "@class": ".LogEventRequest",
  "eventKey": "SCORE",
  "VALUE": 500,
  "FLIPS": 5,
  "STAGE": "STAGE0_6",
  "STARS": 10,
  "LEVEL": 10

The only values that really matter here now are VALUE and STAGE.
So when STAGE is a non existing partition. It gets created. But half of the time, the partition is created, but no entry is made on the board..


Hi Bart

I have tested this and could not get the error, 

Is this only happening with a "STAGE"  that does not exist yet.

How often is this happening?

Are you partitioning on anything other than Stage?



Hi Katie,

If I follow these exact steps in the test harness the problem happens:



  "@class": ".AuthenticationRequest",
  "password": "test",
  "userName": "tester"



  "@class": ".LogEventRequest",
  "eventKey": "SCORE",
  "VALUE": 999,
  "FLIPS": 5,
  "STAGE": "aNewTestStage",
  "STARS": 5,
  "LEVEL": 5

 Then go to Manage->Leaderboards and view STAGE.STAGES.aNewTestStage.
In my case, the partition is created but no entries are found...

Hard to say how often this happens but it looks like on every first log event for a new partition... though I am not completely sure... I am not partitioning on anything other than Stage. Thanks.


Hi Bart

I have copied the code provided and set up a leaderboard to test but I am not getting any of these issues.

Can you explain(screenshots would be really helpful) how your leaderboard and partitions are set up?



I've included screenshots of my setup.

STAGE is the stage ID. Because I want users to create custom levels, the leaderboard partition could be created on the fly...
STARS is a supplemental value that should only be updated when a higher value is reached.
LEVEL is the player level. I have put this in the leaderboard because when a leaderboard is retrieved, I want to display each users level next to their display name. Every time a player completes a stage LEVEL is submitted and only updated when it is larger.
Then there's FLIPS, which doesn't affect the ranking.

I hope I'm clear. Everything seems to work OK, except when a new score event is logged on a non-existent partition. the partition gets created but no entry is made...

Also, looking at this I wonder if there's a better way to keep track of STARS and LEVEL...


Hi Bart

I think I may have found the problem, you said Level only updates when it is larger.

But when starting a new partition level has no default value. 

In your event set up for "SCORE" can you set the Default Value of "LEVEL" to 0.

Let me know if this fixes the problem.



Thanks again for the help. But no luck...

Might it be there is a problem with the fact that there are 2 maximum values in the leaderboard. SCORE and STARS both have group set to maximum. It seems to does what I want it do do as I explained above, but I can't quite wrap my head around how the system actually works. Both SCORE and STARS apply to the partition itself. But the LEVEL value should apply to all partitions at once... which it does. But I don't understand how that value doesn't get partitioned. Maybe there's something wrong there.

I'm sorry if this is all very confusing ;)

Login to post a comment