[iOS-GameCenter] Can't get it to work

Greetings, I’ve been adding the last touches for my upcoming game app, but I’m stuck with integrating game center to it.
I have made a button (gameCenterButton) appear after the player dies, what I want is when the player clicks on it, I want GameCenter to show a leaderboard, but it’s not working, I’m sure I’ve done it wrong, I came for help :slight_smile:
The code:
 

----------- \*\* those are written at the very beginning of the code ----------- local gameNetwork = require ( "gameNetwork" ) local loggedIntoGC = false ----------- local gameCenterButton = display.newImageRect(gameGroup, "assets/game\_center.png", 80, 50) -- gamecenter button gameCenterButton.x = \_W / 2 + 250 gameCenterButton.y = \_H / 2 + 110 gameCenterButton.alpha = 0 gameCenterButton:addEventListener("touch", gameCenter) -- gamecenter button touch event gameCenter = function( event ) local t = event.target if event.phase == "began" then display.getCurrentStage():setFocus( t ) t.isFocus = true t.alpha = 0.5 elseif t.isFocus then if event.phase == "ended" then display.getCurrentStage():setFocus( nil ) t.isFocus = false t.alpha = 1 --Check bounds. If we are in it then click! local b = t.contentBounds if event.x \>= b.xMin and event.x \<= b.xMax and event.y \>= b.yMin and event.y \<= b.yMax then -- Hide the ad hideAdMobAd() -- called after the "init" request has completed 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 -- function to listen for system events local function onSystemEvent( event ) if event.type == "applicationStart" then gameNetwork.init( "gamecenter", initCallback ) return true end end Runtime:addEventListener( "system", onSystemEvent ) gameNetwork.show("leaderboards", { leaderboard = { timeScope = "Week"}}) end end end end

A few questions I would like to ask;

  • Is the gamecenter fully implemented in corona only, or I have to do some things in “iTunes Connect”?
  • What is “sandbox mode” ?

I would appreciate your help :slight_smile:

Game Center is never initialized with your code.

You’ll need to move the init block out of your gemeCenter function.

-- called after the "init" request has completed 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 -- function to listen for system events local function onSystemEvent( event ) if event.type == "applicationStart" then gameNetwork.init( "gamecenter", initCallback ) return true end end Runtime:addEventListener( "system", onSystemEvent )

Yes, you have to set up things in iTunes connect to work.  This is where you define your leaderboards, achievements and other features.  Then you have to enable it.

Then while you build with an AdHoc or Developer profile, it will connect to Sandbox to test.  There are some quirks with using Sandbox, and you cant use a real AppleID (one that is used in production) to use in Sandbox.  You have to have a an AppleID specifically to login to Sandbox with.

Okay I seem to have solved the game center problem, but after I solved it, it divided into two more problems, and I can’t seem to solve them, I have set up my game center in iTunes Connect, including achievements and a leaderboard, first issue is when testing the game on my iPhone, game center works totally fine, it logs in automatically, but when clicking on the game center button, on the “Leaderboard” tab it says “No Items” /and “No leaderboard”.

The second issue is with the achievements, I have connected the achievements in iTunes Connect and the game, but for example I do score 10 points but it doesn’t unlock anything, I don’t see a banner or something appear, I also checked the achievements tab in game center, I haven’t unlocked anything at all…I need a solution asap please!

Here’s the code:

from the game file:

local achievements = {} &nbsp;&nbsp; &nbsp;achievements.BronzeMedal = "com.xxxxxx.myAchievementReferenceName" &nbsp;&nbsp; &nbsp;achievements.SilverMedal = "com.xxxxxx.myAchievementReferenceName" &nbsp;&nbsp; &nbsp;achievements.GoldMedal = "com.xxxxxx.myAchievementReferenceName" &nbsp;&nbsp; &nbsp;achievements.PlatinumMedal = "com.xxxxxx.myAchievementReferenceName" &nbsp;&nbsp; &nbsp;achievements.RainbowMedal = "com.xxxxxx.myAchievementReferenceName" &nbsp;&nbsp; &nbsp;achievements.ChuckMedal = "com.xxxxxx.myAchievementReferenceName" local function displayScores(event) -- if score \> highscore then highscoreFile = io.open(system.pathForFile("highscore", system.DocumentsDirectory), "w") highscore = score highscoreFile:write("" .. score) highscoreFile:close() highscoreFile = nil end end elseif event.phase == "ended" and not isGameOver then if event.other.isSensor then score = score + 1 if score \> highscore then scoreLabel.text = "" .. score .. "!" else scoreLabel.text = "" .. score end playSound("score") if loggedIntoGC then if score \>= 10 then gameNetwork.request( "unlockAchievement", { achievement = { identifier=achievements["BronzeMedal"], showsCompletionBanner=true, } }); elseif score \>= 30 then gameNetwork.request( "unlockAchievement", { achievement = { identifier=achievements["SilverMedal"], showsCompletionBanner=true, } }); elseif score \>= 60 then gameNetwork.request( "unlockAchievement", { achievement = { identifier=achievements["GoldMedal"], showsCompletionBanner=true, } }); elseif score \>= 150 then gameNetwork.request( "unlockAchievement", { achievement = { identifier=achievements["PlatinumMedal"], showCompletionBanner=true, } }); elseif score \>= 250 then gameNetwork.request ( "unlockAchievement", { achievement = { identifier=achievements["RainbowMedal"], showCompletionBanner=true, } }); elseif score \>= 500 then gameNetowork.request ( "unlockAchievement", { achievement = { identifier=achievements["ChuckMedal"], showCompletionBanner=true, } }); end end local function onSubmitScore( event ) if loggedIntoGC then gameNetwork.request( "setHighScore", { localPlayerScore={ category="com.xxx.myLeaderboardID" , value=score }, listener=requestCallback } ); else offlineAlert(); end end end end end

from the menu file, before the game has started:

 

gameTapped = function (event) local t = event.target if event.phase == "began" then display.getCurrentStage():setFocus( t ) t.isFocus = true t.alpha = 0.1 elseif t.isFocus then if event.phase == "ended" then display.getCurrentStage():setFocus( nil ) t.isFocus = false t.alpha = 1 --Check bounds. If we are in it then click! local b = t.contentBounds if event.x \>= b.xMin and event.x \<= b.xMax and event.y \>= b.yMin and event.y \<= b.yMax then playSound("select") gameNetwork.show( "leaderboards", { leaderboard = {timeScope="Week"}} ) gameNetwork.request( "loadScores", { leaderboard = { category="com.xxxxxx.myLeaderboardID", playerScope="Global", -- Global, FriendsOnly timeScope="AllTime", -- AllTime, Week, Today range={1,5} }, listener=requestCallback }) end end end return true end

I would really appreciate it if you could help me!

Can someone help me asap please? this is the only barrier that is preventing me from releasing my game :\ I would really appreciate.

Game Center is never initialized with your code.

You’ll need to move the init block out of your gemeCenter function.

-- called after the "init" request has completed 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 -- function to listen for system events local function onSystemEvent( event ) if event.type == "applicationStart" then gameNetwork.init( "gamecenter", initCallback ) return true end end Runtime:addEventListener( "system", onSystemEvent )

Yes, you have to set up things in iTunes connect to work.  This is where you define your leaderboards, achievements and other features.  Then you have to enable it.

Then while you build with an AdHoc or Developer profile, it will connect to Sandbox to test.  There are some quirks with using Sandbox, and you cant use a real AppleID (one that is used in production) to use in Sandbox.  You have to have a an AppleID specifically to login to Sandbox with.

Okay I seem to have solved the game center problem, but after I solved it, it divided into two more problems, and I can’t seem to solve them, I have set up my game center in iTunes Connect, including achievements and a leaderboard, first issue is when testing the game on my iPhone, game center works totally fine, it logs in automatically, but when clicking on the game center button, on the “Leaderboard” tab it says “No Items” /and “No leaderboard”.

The second issue is with the achievements, I have connected the achievements in iTunes Connect and the game, but for example I do score 10 points but it doesn’t unlock anything, I don’t see a banner or something appear, I also checked the achievements tab in game center, I haven’t unlocked anything at all…I need a solution asap please!

Here’s the code:

from the game file:

local achievements = {} &nbsp;&nbsp; &nbsp;achievements.BronzeMedal = "com.xxxxxx.myAchievementReferenceName" &nbsp;&nbsp; &nbsp;achievements.SilverMedal = "com.xxxxxx.myAchievementReferenceName" &nbsp;&nbsp; &nbsp;achievements.GoldMedal = "com.xxxxxx.myAchievementReferenceName" &nbsp;&nbsp; &nbsp;achievements.PlatinumMedal = "com.xxxxxx.myAchievementReferenceName" &nbsp;&nbsp; &nbsp;achievements.RainbowMedal = "com.xxxxxx.myAchievementReferenceName" &nbsp;&nbsp; &nbsp;achievements.ChuckMedal = "com.xxxxxx.myAchievementReferenceName" local function displayScores(event) -- if score \> highscore then highscoreFile = io.open(system.pathForFile("highscore", system.DocumentsDirectory), "w") highscore = score highscoreFile:write("" .. score) highscoreFile:close() highscoreFile = nil end end elseif event.phase == "ended" and not isGameOver then if event.other.isSensor then score = score + 1 if score \> highscore then scoreLabel.text = "" .. score .. "!" else scoreLabel.text = "" .. score end playSound("score") if loggedIntoGC then if score \>= 10 then gameNetwork.request( "unlockAchievement", { achievement = { identifier=achievements["BronzeMedal"], showsCompletionBanner=true, } }); elseif score \>= 30 then gameNetwork.request( "unlockAchievement", { achievement = { identifier=achievements["SilverMedal"], showsCompletionBanner=true, } }); elseif score \>= 60 then gameNetwork.request( "unlockAchievement", { achievement = { identifier=achievements["GoldMedal"], showsCompletionBanner=true, } }); elseif score \>= 150 then gameNetwork.request( "unlockAchievement", { achievement = { identifier=achievements["PlatinumMedal"], showCompletionBanner=true, } }); elseif score \>= 250 then gameNetwork.request ( "unlockAchievement", { achievement = { identifier=achievements["RainbowMedal"], showCompletionBanner=true, } }); elseif score \>= 500 then gameNetowork.request ( "unlockAchievement", { achievement = { identifier=achievements["ChuckMedal"], showCompletionBanner=true, } }); end end local function onSubmitScore( event ) if loggedIntoGC then gameNetwork.request( "setHighScore", { localPlayerScore={ category="com.xxx.myLeaderboardID" , value=score }, listener=requestCallback } ); else offlineAlert(); end end end end end

from the menu file, before the game has started:

 

gameTapped = function (event) local t = event.target if event.phase == "began" then display.getCurrentStage():setFocus( t ) t.isFocus = true t.alpha = 0.1 elseif t.isFocus then if event.phase == "ended" then display.getCurrentStage():setFocus( nil ) t.isFocus = false t.alpha = 1 --Check bounds. If we are in it then click! local b = t.contentBounds if event.x \>= b.xMin and event.x \<= b.xMax and event.y \>= b.yMin and event.y \<= b.yMax then playSound("select") gameNetwork.show( "leaderboards", { leaderboard = {timeScope="Week"}} ) gameNetwork.request( "loadScores", { leaderboard = { category="com.xxxxxx.myLeaderboardID", playerScope="Global", -- Global, FriendsOnly timeScope="AllTime", -- AllTime, Week, Today range={1,5} }, listener=requestCallback }) end end end return true end

I would really appreciate it if you could help me!

Can someone help me asap please? this is the only barrier that is preventing me from releasing my game :\ I would really appreciate.

Bump?

Bump?