Google Play Game Service - Get current player's leaderboard score

Hello fellow devs,

would be great if anyone could help me figure out how to get the leaderboard score of the currently logged in user.

For Game Center you get event.localPlayerScore.value but I can’t seem to find the equivalent for Google Play Game Services. 

I though of this but I’m not sure it always returns the player’s score or someone else’s:

local function loadScoresListener(event) if event.data then print("Player score is " .. event.data[1].value) end end gameNetwork.request("loadScores", { leaderboard = { category = leaderBoardID, playerScope = "FriendsOnly", -- Global, FriendsOnly timeScope = "AllTime", -- AllTime, Week, Today range = {1,1}, playerCentered = true, }, listener = loadScoresListener })

Thanks.

I had the same problem and haven’t found any other solution but to store scores on a remote server. I tried this solution and it seemed to work until I realized that every player gets MY highscore from the leaderboard :D.

Here is a good read about how to communicate with a server using Corona SDK.

Best, Ilya

Actually the solution I though about worked, you can use the following code to get the current player’s leaderboard score:

local function scoresListener(event) if event then if event.data and event.data[1] and event.data[1].value then print("The current score is " .. event.data[1].value) end end end gc.request("loadScores", { leaderboard = { category = leaderboard\_id, playerScope = "FriendsOnly", -- Global, FriendsOnly timeScope = "AllTime", -- AllTime, Week, Today range = {1,1}, playerCentered = true, }, listener = scoresListener })

Thanks anyways ilystone.

To anyone facing this problem, I think abiasi’s solution works with one caveat.  If the player is signing into the game for the very first time, never having played the game or joined the leaderboard before, the player centered flag will return a score, but since they do not have at least one, it will be the top score on the leaderboard, if they have some friends who have played before.  Need some kind of check here to prevent this issue.  Just not sure what yet.  If I figure it out I will post it.  I guess a work-around would be to do at least one post to the leaderboard for the player before pulling.  I wonder if I could post scores of 0 on the leaderboards for a player the first time they sign in?

That’s exactly what happened in my case… And I think one should just check if it’s the first time they logged in or not. And if it is, that means that the highscore is the one stored locally, so no need to update the value from Google Play. Also at that moment we can update Google Play score with the current local score.

Well I was kind of using getting the current player’s score to sync up scores between multiple devices.  So I have to figure out something other than this is the first time someone has logged into a device.

Does anyone know if GPGS returns the PlayerID field when getting the high scores?  If so I can probably just match this up against the result from the loadLocalPlayer request.  If I get time to try this tonight and it works I will ping this thread back.

In my case the solution turned out to be just to push a score of zero to each leaderboard for the player the first time they log in.  I could see this not working if your leaderboard rankings run from low to high but mine do not.

I had the same problem and haven’t found any other solution but to store scores on a remote server. I tried this solution and it seemed to work until I realized that every player gets MY highscore from the leaderboard :D.

Here is a good read about how to communicate with a server using Corona SDK.

Best, Ilya

Actually the solution I though about worked, you can use the following code to get the current player’s leaderboard score:

local function scoresListener(event) if event then if event.data and event.data[1] and event.data[1].value then print("The current score is " .. event.data[1].value) end end end gc.request("loadScores", { leaderboard = { category = leaderboard\_id, playerScope = "FriendsOnly", -- Global, FriendsOnly timeScope = "AllTime", -- AllTime, Week, Today range = {1,1}, playerCentered = true, }, listener = scoresListener })

Thanks anyways ilystone.

To anyone facing this problem, I think abiasi’s solution works with one caveat.  If the player is signing into the game for the very first time, never having played the game or joined the leaderboard before, the player centered flag will return a score, but since they do not have at least one, it will be the top score on the leaderboard, if they have some friends who have played before.  Need some kind of check here to prevent this issue.  Just not sure what yet.  If I figure it out I will post it.  I guess a work-around would be to do at least one post to the leaderboard for the player before pulling.  I wonder if I could post scores of 0 on the leaderboards for a player the first time they sign in?

That’s exactly what happened in my case… And I think one should just check if it’s the first time they logged in or not. And if it is, that means that the highscore is the one stored locally, so no need to update the value from Google Play. Also at that moment we can update Google Play score with the current local score.

Well I was kind of using getting the current player’s score to sync up scores between multiple devices.  So I have to figure out something other than this is the first time someone has logged into a device.

Does anyone know if GPGS returns the PlayerID field when getting the high scores?  If so I can probably just match this up against the result from the loadLocalPlayer request.  If I get time to try this tonight and it works I will ping this thread back.

In my case the solution turned out to be just to push a score of zero to each leaderboard for the player the first time they log in.  I could see this not working if your leaderboard rankings run from low to high but mine do not.

for anyone that would like to have get the user avatar too, vote on this : 

http://feedback.coronalabs.com/forums/188732-corona-sdk-feature-requests-feedback/suggestions/5545745-google-play-games-services-return-avatar-url

for anyone that would like to have get the user avatar too, vote on this : 

http://feedback.coronalabs.com/forums/188732-corona-sdk-feature-requests-feedback/suggestions/5545745-google-play-games-services-return-avatar-url