GameCenter: How to get players highscore?

I’m trying to get a players highscore by using event.localPlayerScore.value but can’t get it to work.

Does anybody have a code sample how this should work and where I can see this event? I tried to check this in the listener but it seems not be known?

I know these kind of replies haven’t been popular in the recent weeks, but here’s the documentation with the required information and sample code: https://docs.coronalabs.com/plugin/gameNetwork-apple/request.html

The plugin’s main page also has a link to an entire sample project that uses achievements and leaderboards: https://github.com/coronalabs/plugins-sample-gamenetwork-apple

Thx! This was exactly what I was looking into. But I can’t figure out how I can load a players highscore from gamecenter to use it in the game. … ?

This may be a silly question, but “Are you storing their highscore in game center first?”   i.e. Are you tracking score locally and later submitting it to game center? 

The docs read:
 

When handling the results of a “loadScores” call, event.data in the callback listener is an array of items (tables), each of which contains the following properties:

event.data[1].playerID  – ID of the first player in the request

event.data[3].rank      – Rank of the third player in the request

In addition, the event.localPlayerScore table is accessible for the logged-in player. This contains all of the properties shown above.

event.localPlayerScore.playerID

event.localPlayerScore.rank

 

So, if the player is logged in, you can get their score value by “event.localPlayerScore.value”. Otherwise you need to use event.data as also described above.

I’m storing a highscore in gamecenter when there is a new highscore. And in case someone is deinstalling his game and then want to install it again I need access to his gamecenter highscore data to restore his previous highscore in the new install.

I did some more tests and it seems the local user is not logged in, so I can not get the correct data BUT I don’t understand why this is happening, because I get the welcome info on top of the phone which shows I’m looged into gamecenter correctly. I can call the leaderboard and am listed as “friend” with my top score in the leaderboard list. But when trying to get the info for my logged in user it fails.

Is there a sample on how a user can log into gamecenter at start? So it is not using the “auto” login?

This seems to be the problem here… I get the message “Welcome back XY” but can not access this events

event.localPlayerScore.playerID

event.localPlayerScore.rank

 

 

because I get the message the player is not logged into gamecenter! But why can I see the global leaderboard then?

Any help / ideas?

For GameCenter, you have to:

.init()

.login()

and then call 

.loadLocalPlayer()

and 

.loadScores() 

Most people will take the successful initialization to call login so that they are automatically logged in.

Rob

I know these kind of replies haven’t been popular in the recent weeks, but here’s the documentation with the required information and sample code: https://docs.coronalabs.com/plugin/gameNetwork-apple/request.html

The plugin’s main page also has a link to an entire sample project that uses achievements and leaderboards: https://github.com/coronalabs/plugins-sample-gamenetwork-apple

Thx! This was exactly what I was looking into. But I can’t figure out how I can load a players highscore from gamecenter to use it in the game. … ?

This may be a silly question, but “Are you storing their highscore in game center first?”   i.e. Are you tracking score locally and later submitting it to game center? 

The docs read:
 

When handling the results of a “loadScores” call, event.data in the callback listener is an array of items (tables), each of which contains the following properties:

event.data[1].playerID  – ID of the first player in the request

event.data[3].rank      – Rank of the third player in the request

In addition, the event.localPlayerScore table is accessible for the logged-in player. This contains all of the properties shown above.

event.localPlayerScore.playerID

event.localPlayerScore.rank

 

So, if the player is logged in, you can get their score value by “event.localPlayerScore.value”. Otherwise you need to use event.data as also described above.

I’m storing a highscore in gamecenter when there is a new highscore. And in case someone is deinstalling his game and then want to install it again I need access to his gamecenter highscore data to restore his previous highscore in the new install.

I did some more tests and it seems the local user is not logged in, so I can not get the correct data BUT I don’t understand why this is happening, because I get the welcome info on top of the phone which shows I’m looged into gamecenter correctly. I can call the leaderboard and am listed as “friend” with my top score in the leaderboard list. But when trying to get the info for my logged in user it fails.

Is there a sample on how a user can log into gamecenter at start? So it is not using the “auto” login?

This seems to be the problem here… I get the message “Welcome back XY” but can not access this events

event.localPlayerScore.playerID

event.localPlayerScore.rank

 

 

because I get the message the player is not logged into gamecenter! But why can I see the global leaderboard then?

Any help / ideas?

For GameCenter, you have to:

.init()

.login()

and then call 

.loadLocalPlayer()

and 

.loadScores() 

Most people will take the successful initialization to call login so that they are automatically logged in.

Rob