question

[not provided] avatar image
[not provided] asked

Get number 1 on leadboard

I was wondering how I could get the number 1 score on top of the leaderboard as a var in Unity.

Cheers

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.

brendan avatar image
brendan answered

Calling GetLeaderboard with the StartPosition set to 0 will always return the top entries in the leaderboard, as shown in the example, here: https://api.playfab.com/Documentation/Client/method/GetLeaderboard.

10 |1200

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

[not provided] avatar image
[not provided] answered

So is that StartPosition?

On a slightly seperate note, it says that that is an int32, does this mean a highscore cannot be a float?

10 |1200

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

brendan avatar image
brendan answered

Sorry, yes - StartPosition. I'll update the response above, to clarify. And yes, as in other services like PSN and XBL, leaderboards are generated from int values. If you want to have floating point values, you would need to store them using an int value (multiplying them, for instance), and then do the math conversion when displaying the scores to the player.

10 |1200

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

[not provided] avatar image
[not provided] answered

Ah, cheers for you help!

10 |1200

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

[not provided] avatar image
[not provided] answered

Oh hold on a minute, just rereading your first comment, just to clarify, will returning start position 0 just get me one int value which is number 1 (or technically 0) on the leaderboard as a var?

10 |1200

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

brendan avatar image
brendan answered

All scores have a position in the leaderboard, with that position being zero-based. And the scores are always listed in ascending order, so if you have players with scores of 1, 2, and 3, they would be returned as:

Position 0 - score 3

Position 1 - score 2

Position 2 - score 1

10 |1200

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

[not provided] avatar image
[not provided] answered

Ah okay, so if I did (obviously this isnt correctly written, but Im sure you get the idea):

var TopScore = GetLeaderboard.Position.0

Then TopScore would = 3

10 |1200

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

brendan avatar image
brendan answered

Correct, the value for the entry in position 0 would be the highest score on the leaderboard.

10 |1200

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

[not provided] avatar image
[not provided] answered

Fantastic!

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.