Leaderboard in Game Center

Hello all,

I searched on web about implementing very basic usage of the Apple Game Center in my game, but could not find a clear example as a video or code.

Here is the specs:

-When game ends, update the score at Leaderboard in GameCenter, if the score greater than best score.

-When leaderboard button is clicked, browse to the leaderboard at GameCenter.

example parameters:

about leaderboard

Type: Single, Reference Name: bestofX, Leaderboard ID: bestofX

about game

local best;

local score;

I think this is a very basic concept for all games, If anyone replies this question with example code, the answer will be useful for all newbies like me.

you dont need to check if the high score is greater than a previous high score

just send the score to GameCenter and it will check for you

I use the following to send my score

local function postingScore( event ) -- The shown Game Center popup was closed. end local function sendHighScore () gameNetwork.request( "setHighScore", { localPlayerScore = { category="highScoreTable", value=hScore }, listener = postingScore }) end

then for a button so you can browse the leaderboards add the following to a button

local function onGameNetworkPopupDismissed( event ) -- The shown Game Center popup was closed. end local leaderboardButton= function( event ) if event.phase == "release" then -- Display the leaderboard. gameNetwork.show( "leaderboards", { leaderboard = {timeScope="AllTime"}, listener=onGameNetworkPopupDismissed } ) end end

hello again,

I tried to implement it. first I made 


local gameNetwork = require “gameNetwork”

loggedIntoGC = false

local function initCallback( event )

    if event.data then

        loggedIntoGC = true

        native.showAlert( “Success!”, “User has logged into Game Center”, { “OK” } )

    else

        loggedIntoGC = false

        native.showAlert( “Fail”, “User is not logged into Game Center”, { “OK” } )

    end

end

local function onSystemEvent( event ) 

    if event.type == “applicationStart” then

        gameNetwork.init( “gamecenter”, initCallback )

        return true

    end

end

Runtime:addEventListener( “system”, onSystemEvent )


to check my connection to game center and after i implemented your sample code in my project


local function postingScore( event )

    – The shown Game Center popup was closed.

end

local function sendHighScore ()

    gameNetwork.request( “setHighScore”,

    {

        localPlayerScore = { category=“bestofX”, value=score },

        listener = postingScore

    })

end


and i called this function at my endcondition as 


if loggedIntoGC then sendHighScore() end


in my other lua file i implemented game center leaderboard button

-----local function onGameNetworkPopupDismissed( event )

    – The shown Game Center popup was closed.

end

local function GoToLeaderboard(  )

  if loggedIntoGC then

        gameNetwork.show( “bestoffragile”, { leaderboard = {timeScope=“AllTime”},

        listener=onGameNetworkPopupDismissed } )

  end

end


and call this method as onRelease of a button

why my game center implementation does not work?

you dont need to check if the high score is greater than a previous high score

just send the score to GameCenter and it will check for you

I use the following to send my score

local function postingScore( event ) -- The shown Game Center popup was closed. end local function sendHighScore () gameNetwork.request( "setHighScore", { localPlayerScore = { category="highScoreTable", value=hScore }, listener = postingScore }) end

then for a button so you can browse the leaderboards add the following to a button

local function onGameNetworkPopupDismissed( event ) -- The shown Game Center popup was closed. end local leaderboardButton= function( event ) if event.phase == "release" then -- Display the leaderboard. gameNetwork.show( "leaderboards", { leaderboard = {timeScope="AllTime"}, listener=onGameNetworkPopupDismissed } ) end end

hello again,

I tried to implement it. first I made 


local gameNetwork = require “gameNetwork”

loggedIntoGC = false

local function initCallback( event )

    if event.data then

        loggedIntoGC = true

        native.showAlert( “Success!”, “User has logged into Game Center”, { “OK” } )

    else

        loggedIntoGC = false

        native.showAlert( “Fail”, “User is not logged into Game Center”, { “OK” } )

    end

end

local function onSystemEvent( event ) 

    if event.type == “applicationStart” then

        gameNetwork.init( “gamecenter”, initCallback )

        return true

    end

end

Runtime:addEventListener( “system”, onSystemEvent )


to check my connection to game center and after i implemented your sample code in my project


local function postingScore( event )

    – The shown Game Center popup was closed.

end

local function sendHighScore ()

    gameNetwork.request( “setHighScore”,

    {

        localPlayerScore = { category=“bestofX”, value=score },

        listener = postingScore

    })

end


and i called this function at my endcondition as 


if loggedIntoGC then sendHighScore() end


in my other lua file i implemented game center leaderboard button

-----local function onGameNetworkPopupDismissed( event )

    – The shown Game Center popup was closed.

end

local function GoToLeaderboard(  )

  if loggedIntoGC then

        gameNetwork.show( “bestoffragile”, { leaderboard = {timeScope=“AllTime”},

        listener=onGameNetworkPopupDismissed } )

  end

end


and call this method as onRelease of a button

why my game center implementation does not work?