question

Claire Rochelmeyer avatar image
Claire Rochelmeyer asked

How to check if Leaderboard exists or not

As the UpdatePlayerStatistic request causes "Statistics not currently defined [to] be added", I need to be able to ensure the given StatisticName corresponds to an existing Leaderboard. The server.GetLeaderboard request returns without issue even if there is no existing Leaderboard with the given StatisticName. To be clear, the result the request returns is:

{"Leaderboard":[],"Version":0}

Is there a way for me to differentiate from this result that the Leaderboard *doesn't* exist and not that it does exist and is either empty, or recently versioned?

Or is there a different request that I can call? As far as I'm aware, I can't and shouldn't be calling admin api requests from CloudScript, otherwise admin.GetPlayerStatisticDefinitions would be an option?

CloudScript
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

You can use this server API GetPlayerStatisticVersions on CloudScript to check if the statistic exist. If the statistic does not exist, it will produce error like this:

{

"code": 400,

"status": "BadRequest",

"error": "StatisticNotFound",

"errorCode": 1195,

"errorMessage": "A statistic does not exist with the specified ID or name"

}

You can use try-catch syntax on CloudScript to catch the error and update the statistic accordingly.

It is true that the admin API isn’t available on CloudScript, there is no such predefined variable named “admin”.

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.

Claire Rochelmeyer avatar image Claire Rochelmeyer commented ·

This worked perfectly, thank you!

0 Likes 0 ·

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.