Implement Game Center leaderboard

Hello, I’m trying to implement Game Center leaderboard, but doesn’t work. Can anyone help me. This is my code with I tried:

build.settings

settings = { plugins = { ["CoronaProvider.gameNetwork.apple"] = { publisherId = "com.coronalabs", supportedPlatforms = { iphone=true } }, }, }

on lua script:

local gameNetwork = require( "gameNetwork" ) composer.setVariable( "currentScore", 100 ) composer.setVariable( "currentLeaderboardID", "MYIDNUMBER" ) composer.setVariable( "currentLeaderboardTitle", "MYNAMEOFLEADERBOARD" ) function onClickGameCenter() --this function is called when someone click on game center icon localPlayerScore = { category=composer.getVariable( "currentLeaderboardID" ), value=composer.getVariable( "currentScore" ) }, gameNetwork.show( "leaderboards", { leaderboard={ category=composer.getVariable( "currentLeaderboardID" ) } } ) end

I hope that someone can help me.
Thanks and kind regards

 

Hi @dario.karin95,

Did you inspect our sample project for Game Center? This project implements a leaderboard, and you can basically use that to model your own. It’s located in your local Corona application folder here:

CoronaSDK-XXXX > SampleCode > GameNetwork > GameCenter

Hope this helps,

Brent

Thank you Brent for your response. I already tried with SampleCode but this is not what I need.  

I used a code as I mentioned on first post. My main.lua is:
 

local gameNetwork = require( "gameNetwork" ) local loggedIntoGC = false local function initCallback( event )     if ( event.type == "showSignIn" ) then         -- This is an opportunity to pause your game or do other things you might need to do while the Game Center Sign-In controller is up.     elseif ( event.data ) then         loggedIntoGC = true         native.showAlert( "Success!", "", { "OK" } )     end end local function onSystemEvent( event )      if ( event.type == "applicationStart" ) then         gameNetwork.init( "gamecenter", initCallback )         return true     end end Runtime:addEventListener( "system", onSystemEvent )

I received WARNING on corona simulator console: WARNING: CoronaProvider.gameNetwork.gamecenter is not configured in build.settings 

You can see on first post how my build.settings look like.

Kind regards

Try

settings = { plugins = { ["CoronaProvider.gameNetwork.apple"] = { publisherId = "com.coronalabs", supportedPlatforms = { iphone=true, ["iphone-sim"]=true } }, }, }

The error in the simulator is because you didn’t include [“iphone-sim”] = true

–john

I have the same error after that.

@dario.karin95, How are you testing your code? On the Corona Simulator or the Xcode Simulator or an iOS device?

@animonger On iOS device. Can you check the accuracy of my code.

Code is: 

build.settings
 

settings = {orientation = { default = "portrait", }, plugins =     {        ["plugin.google.play.services"] =         {             publisherId = "com.coronalabs",             supportedPlatforms = { iphone=true, android=true }         },                   ["CoronaProvider.gameNetwork.apple"] =         {             publisherId = "com.coronalabs",             supportedPlatforms = { iphone=true }         },     }, }

main.lua
 

local gameNetwork = require( "gameNetwork" )-- local loggedIntoGC = false local function initCallback( event )    if ( event.type == "showSignIn" ) then        -- This is an opportunity to pause your game or do other things you might need to do while the Game Center Sign-In controller is up.    elseif ( event.data ) then        loggedIntoGC = true        native.showAlert( "Success!", "", { "OK" } )    end end local function onSystemEvent( event )     if ( event.type == "applicationStart" ) then        gameNetwork.init( "gamecenter", initCallback )        return true    end end Runtime:addEventListener( "system", onSystemEvent )

restart.lua (this is shown to user when he lost the game, there you can see score, highscore, buttons, one button is reserved for game center)
 

local gameNetwork = require( "gameNetwork" ) composer.setVariable( "currentScore", 100 ) composer.setVariable( "currentLeaderboardID", "MyIDFromItunesConnect" ) composer.setVariable( "currentLeaderboardTitle", "NameOfLeaderboard" )

function onClickGameCenter() --this function is called when user press the gamecenter button localPlayerScore = { category=composer.getVariable( "currentLeaderboardID" ), value=composer.getVariable( "currentScore" ) }, gameNetwork.show( "leaderboards", { leaderboard={ category=composer.getVariable( "currentLeaderboardID" ) } } ) end

Hi @dario.karin95,

Did you inspect our sample project for Game Center? This project implements a leaderboard, and you can basically use that to model your own. It’s located in your local Corona application folder here:

CoronaSDK-XXXX > SampleCode > GameNetwork > GameCenter

Hope this helps,

Brent

Thank you Brent for your response. I already tried with SampleCode but this is not what I need.  

I used a code as I mentioned on first post. My main.lua is:
 

local gameNetwork = require( "gameNetwork" ) local loggedIntoGC = false local function initCallback( event )     if ( event.type == "showSignIn" ) then         -- This is an opportunity to pause your game or do other things you might need to do while the Game Center Sign-In controller is up.     elseif ( event.data ) then         loggedIntoGC = true         native.showAlert( "Success!", "", { "OK" } )     end end local function onSystemEvent( event )      if ( event.type == "applicationStart" ) then         gameNetwork.init( "gamecenter", initCallback )         return true     end end Runtime:addEventListener( "system", onSystemEvent )

I received WARNING on corona simulator console: WARNING: CoronaProvider.gameNetwork.gamecenter is not configured in build.settings 

You can see on first post how my build.settings look like.

Kind regards

Try

settings = { plugins = { ["CoronaProvider.gameNetwork.apple"] = { publisherId = "com.coronalabs", supportedPlatforms = { iphone=true, ["iphone-sim"]=true } }, }, }

The error in the simulator is because you didn’t include [“iphone-sim”] = true

–john

I have the same error after that.

@dario.karin95, How are you testing your code? On the Corona Simulator or the Xcode Simulator or an iOS device?

@animonger On iOS device. Can you check the accuracy of my code.

Code is: 

build.settings
 

settings = {orientation = { default = "portrait", }, plugins =     {        ["plugin.google.play.services"] =         {             publisherId = "com.coronalabs",             supportedPlatforms = { iphone=true, android=true }         },                   ["CoronaProvider.gameNetwork.apple"] =         {             publisherId = "com.coronalabs",             supportedPlatforms = { iphone=true }         },     }, }

main.lua
 

local gameNetwork = require( "gameNetwork" )-- local loggedIntoGC = false local function initCallback( event )    if ( event.type == "showSignIn" ) then        -- This is an opportunity to pause your game or do other things you might need to do while the Game Center Sign-In controller is up.    elseif ( event.data ) then        loggedIntoGC = true        native.showAlert( "Success!", "", { "OK" } )    end end local function onSystemEvent( event )     if ( event.type == "applicationStart" ) then        gameNetwork.init( "gamecenter", initCallback )        return true    end end Runtime:addEventListener( "system", onSystemEvent )

restart.lua (this is shown to user when he lost the game, there you can see score, highscore, buttons, one button is reserved for game center)
 

local gameNetwork = require( "gameNetwork" ) composer.setVariable( "currentScore", 100 ) composer.setVariable( "currentLeaderboardID", "MyIDFromItunesConnect" ) composer.setVariable( "currentLeaderboardTitle", "NameOfLeaderboard" )

function onClickGameCenter() --this function is called when user press the gamecenter button localPlayerScore = { category=composer.getVariable( "currentLeaderboardID" ), value=composer.getVariable( "currentScore" ) }, gameNetwork.show( "leaderboards", { leaderboard={ category=composer.getVariable( "currentLeaderboardID" ) } } ) end