question

Hot Chai avatar image
Hot Chai asked

How to create a daily leaderboard that resets in local time?

I'd like the daily leaderboard in my game to appear to reset in a player's local time zone.

My plan for implementing this was to use either the current or previous version of the leaderboard in my game, depending on the player's local time zone vs the PlayFab leaderboard UTC reset time.

However, I just read in the documentation that the previous version of the leaderboard is only available for writes for 10 minutes after the leaderboard is reset, so that plan won't work.

What's the recommended way to implement my leaderboard?

It's a really confusing and amateurish experience to have the leaderboard day ending at 7pm for some players. Clearly that's not the end of their day and it's completely unexpected behavior for them. Surely there's a way to create a good daily leaderboard experience with PlayFab?

Thanks!

Leaderboards and Statistics
10 |1200

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

Hot Chai avatar image
Hot Chai answered

Simply choosing a different reset schedule will not allow players to compete on the same daily leaderboard in their local time zone, since at any given time players in different time zones will be competing on a different version of the leaderboard.

For example, it might be either the 15th, 16th, or 17th day of March for you right now, depending on your time zone. So at any given time, there must be 3 active (writeable) versions of a daily leaderboard.

Since only one version of the Playfab leaderboards is writeable, 3 separate leaderboards (i.e., with different statistic names) are required to build this feature.

I was able to implement this feature by creating 3 leaderboards and resetting them on a staggered 3-day schedule, such that any given instance of the leaderboard is active for 3 days.

Unfortunately, Playfab cannot be configured to reset a leaderboard every 3 days, and cron does not support this type of schedule, either, so none of the recommendations for resetting the leaderboards are viable. (Also note that Cloudscript does not support Admin API calls, so can't be used for this purpose, either.)

I was able to solve the reset problem by creating an Azure WebJob that runs every 24 hours and resets the next leaderboard in the staggered rotation. I found the WebJob to be much simpler and more appropriate for this task than the Azure Function recommended in the documentation.

I also used this same pattern to create a weekly leaderboard that starts and ends in the player's local time zone using only two leaderboards that are reset on a staggered 14-day schedule (so reset one of the leaderboards every 7 days).

I used the same WebJob that runs every 24 hours to reset the appropriate leaderboards depending on the number of days since a base date mod 3 for daily leaderboards and the week since a base date mod 2 for the weekly leaderboards.

The final step was to use local time in the game to determine which leaderboard the player should access. For the daily leaderboards this is the leaderboard that was reset the day before, and for the weekly leaderboards it is the leaderboard reset the week before.

So it's not trivial, but with multiple instances of each leaderboard and some tricky date calculations in your game and WebJob I'm happy to say it's possible to workaround the Playfab leaderboard limitations and create a great player experience for leaderboards shared across time zones.

1 comment
10 |1200

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

Hot Chai avatar image Hot Chai commented ·

Clarification for the weekly leaderboard: The leaderboards are reset on alternating Sundays and go into active use by players on Mondays. Since each leaderboard is active for 14 days before being reset, it will be available from any time zone. In other words, it is reset before the beginning of the week (Monday) in the earliest time zone and is active past the end of the week in the latest time zone (a 9-day span).

0 Likes 0 ·
Ivan Cai avatar image
Ivan Cai answered

Currently, leaderboards can be reset hourly, at 00:00 UTC for daily, weeky, and monthly. Or you can use the Admin API IncrementPlayerStatisticVersion for custom set. In this case, you can use scheduled task to custom reset. For more operations, please refer to Using Scheduled Task to reset Leaderboard - Playfab Community and Reset top 10 players leaderboard only and maintain other players' statistic,Is there a way to reset the top 10 players in a leaderboard without resetting all other players statistic? - Playfab Community

10 |1200

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

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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