Sign In Register

How can we help you today?

Start a new topic

Daily High Score Leaderboard and Reset

Hi, I am trying to implement daily high score leaderboard.

Scenario - 

Day 1 high score - 500

Day 2 high score - 300 

This score of 300 does not reflect in the leaderboard data because it is less that 500 in spite of this being submitted on the next day.

What I have done - 
1. Added a daily leaderboard with an event "Daily Score" with two attributes Score and Day. Set it to "Reset Daily".

2. I have not created any running totals as shown in the "Timed Leaderboard" tutorials because as per my understanding I do not need that.

3. When retrieving the data for the second day I get a null response as the score 300 was not accepted by the server.

Should be in string format
I'm getting an error for ${today}
Save error: "defaultValue" in /~events/SUBMIT_TP_SCORE_PC/~attributes/DAY is not a valid default value


I am trying to follow the instructions here to make a weekly leaderboard that does not keep using the old scores after reseting but i am getting an error message when attempting to add the DAY attribute to the event. In addition the interface for setting a leaderboard has changed since this was posted.

I get this error if the Data Type is set to Number when the default value is ${today:startOfWeek()}

Save error: "defaultValue" in /~events/submitCoinsEarned/~attributes/DAY is not a valid default value (through reference chain: com.wagerz.devportal.domain.Event["~attributes"])

1 person likes this

Hi Liew,

Yes midnight UTC time is when the leaderboards reset.



Nvm, found the answer. The server time follows UTC 0:00 as mentioned here.

This post is really really helpful to me.

I am also using a daily-reset leaderboard. But the rank is inverse of the score (i.e. lower score higher rank), just a simple DESC to ASC and MAX to MIN would do the trick.

The day code GS used is simply (TODAY() - "1970-1-1")*24*3600*1000. In short, number of seconds since 1970-1-1 to today times 1000.

Next question is, when will GS "step" into next day ? Midnight of which time-zone?

Hi Deftouch, 

You can use the following on the client in Unity to generate the time and shortCode for the LeaderBoardDataRequest. The zeroes are added manually at the end for the milliseconds.

DateTime today = DateTime.UtcNow;
today = new DateTime(today.Year, today.Month, today.Day);
int time = (int)(today.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;

// log of the output




1 person likes this


That's not a valid shortCode, the shortCode for today would be ""

I'll get back to you soon with an example of how to generate the timestamp in Unity.



how should I generate this timestamp on the client side?

if I use "${today}" as my short code I get an empty object.

Hi Deftouch,

No that's the shortCode for todays leaderboard partition. Tomorrow the ${today} expression will generate another timestamp to use to partition the leaderboard. The timestamps returned by this expression will give you midnight of the current day. So 1461801600000 = Thu, 28 Apr 2016 00:00:00. Tomorrows timestamp will be for Fri, 29 Apr 2016 00:00:00 and so on. On the client side if you wanted to display the Daily Leaderboard you would generate the timestamp for the start of the current day and then send a LeaderboardDataRequest with the shortCode "" and the generated shortCode on the end. If you have any other questions just let me know.



just to be clear, will my short code always be "" ?

Hi Deftouch, 

You would use "" as the shortCode to return that days leaderboard data, if the leaderboard partition was saved as "${today}" it would be writing to the same partition day after day. As ${today} gets the unix timestamp for the particular day the score was posted on it will make sure that each days partition is created when a score is posted to it on that day. Hope that makes sense, let me know if you have any other questions.



Thanks for the response. I have implemented all the things that you mentioned but my problem is with the leaderboard short code.

The daily score is getting updated in a leaderboard by the name -

and not in${today} where I would expect it to be.

What short code should I use for recovering this data??

Hi Deftouch,

Whats happening here is the score of 500 is logged on Day1 to your leaderboard, at the end of the day the leaderboard is reset but the running total isn't (this is the important part), as the running isn't reset the score of 300 on Day2 isn't registered as a high score, only scores higher than 500 will be. The running total isn't reset as it may be in use by another leaderboard somewhere else and resetting it may brake it. With a little tweaking you can get the setup you want which I will detail below.

Set your score event up as follows, having the Day Default Value set to ${today} will set that attribute to the epoch time of midnight today, all scores posted will be grouped by the day attribute and partitioned later in the leaderboard. You could also use "${today:startOfWeek()}" to group and partition by week and "${today:startOfMonth()}" to group and partition by month.

You can then set your leaderboard up as follows. The important things to note here, the leaderboard update schedule is RealTime and the Day attribute is set to partition. 

So when a score is posted from now on, the ${today} filter will get the current day and the leaderboard will create a partition for it, the running total data will also be partitioned so in your scenario with this setup, the score of 300 on day2 will register as a high score after 500 was logged on day1. If you then navigate to the manage screen you will be able to view the partitioned data, here I have posted a score of 800. If I posted a score of 70 tomorrow that would be registered as the high score for tomorrow partition. 

Does this sound like it will work for you ? Let me know if you have any further questions.



Login to post a comment