question

Kim Strasser avatar image
Kim Strasser asked

How can I get the remaining time of my leaderboards?

I store a key/value pair of my leaderboards in TitleData. If the value is "true", then there is an active leaderboard.

For example:

I use client API GetTitleData to retrieve the key/value pairs of my currently active leaderboards: Leaderboard-1-1, Leaderboard-1-3, Leaderboard-1-7.

After that, which client API call should I use to get the remaining time of each of those three leaderboards? Is it possible to do this in one API call? Can I use PlayFabClientAPI.GetLeaderboard?

I want to display the remaining time for each leaderboard like this:

Days/Hours/Minutes/Seconds

Is it necessary to calculate the remaining time of each leaderboard myself or does PlayFab already have a method that automatically returns the remaining time until the next leaderboard reset?

I use this code to calculate the remaining time myself:

DateTime NextLeaderboardReset, CurrentTime;
TimeSpan TimeInterval;
int DaysLeft, HoursLeft, MinutesLeft, SecondsLeft;
string Countdown = "";

NextLeaderboardReset = (DateTime)result.Result.NextReset;
CurrentTime = DateTime.UtcNow;
TimeInterval = NextLeaderboardReset - CurrentTime;
Countdown = $"Time left: {TimeInterval.ToString(@"dd\:hh\:mm\:ss")}";
DaysLeft = TimeInterval.Days;
HoursLeft = TimeInterval.Hours;
MinutesLeft = TimeInterval.Minutes;
SecondsLeft = TimeInterval.Seconds;

Edit: I have changed my code. I will store the time of the next leaderboard reset in TitleData for each leaderboard. Then, I don't need to call GetLeaderboard always when I want to get the remaining time:

https://community.playfab.com/questions/49233/how-can-i-get-titledata-json-value-in-the-client.html

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.

1 Answer

·
Rick Chen avatar image
Rick Chen answered

There is no API that gets the remaining time of leaderboard reset. Yes, you can calculate the remaining time as the code snippet you provide. And yes, you can store the leaderboard reset time in the TitleData such that you can retrieve multiple leaderboard reset time in one call.

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.