Hi all–
I have been experimenting with GameCenter on my devices, however I have been unable to make the score properly post to the leaderboard.
Here’s what I have going:
starting GameCenter:
-- game center local gameNetwork = require( "gameNetwork" ) local widget = require( "widget" )
Logging into GameCenter
-- gamecenter login local loggedIntoGC = false local function onSystemEvent( event ) if ( event.type == "applicationStart" ) then gameNetwork.init( "gamecenter", initCallback ) return true end end Runtime:addEventListener( "system", onSystemEvent )
Posting the Score
-- post listener local function requestCallback( event ) if ( event.type == "setHighScore" ) then print( "score posted" ) end end -- create hero collision local function heroCollision( self, event ) if event.phase == "began" then if startNum == 1 then gameNetwork.request( "setHighScore", { localPlayerScore = { category="com.mydomain.leaderboard\_id\_for\_the\_game", value=score }, listener = requestCallback } ) timer.performWithDelay( 1000, continueReset ) end end end timer.performWithDelay( 1000, listener )
Pretty much, the code directly above (last paste) occurs when the game is over on a collision. I have it posting the score to the leaderboard here, then after a second it continues onto resetting the objects on the screen, then after 3 seconds it resets the score (which is being posted to GameCenter) through use in the continueReset function. I would like it to post the score, which is known as the score variable. I referenced it in the code as value=score, is that correct?
I have logged into 2 sandbox accounts and had scores post, however, the score is not appearing in GameCenter. I see the leaderboard in the GameCenter app for the game (sandbox), however no scores are being displayed.
If anybody has any idea as to what I am doing wrong, any help is greatly appreciated.
Thanks!