Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

GameCenter: How to get players highscore?
Started by d.mach Dec 07 2018 03:31 AM

7 replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

d.mach

[GLOBAL: userInfoPane.html]
d.mach
  • Contributor

  • 971 posts
  • Corona SDK

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?

 



[TOPIC: post.html]
#2

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,248 posts
  • Corona SDK

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



[TOPIC: post.html]
#3

d.mach

[GLOBAL: userInfoPane.html]
d.mach
  • Contributor

  • 971 posts
  • Corona SDK

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. ... ?



[TOPIC: post.html]
#4

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,666 posts
  • Corona SDK

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? 



[TOPIC: post.html]
#5

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,248 posts
  • Corona SDK

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.



[TOPIC: post.html]
#6

d.mach

[GLOBAL: userInfoPane.html]
d.mach
  • Contributor

  • 971 posts
  • Corona SDK

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.



[TOPIC: post.html]
#7

d.mach

[GLOBAL: userInfoPane.html]
d.mach
  • Contributor

  • 971 posts
  • Corona SDK

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?



[TOPIC: post.html]
#8

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,681 posts
  • Enterprise

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




[topic_controls]
[/topic_controls]