Game Center Leaderboard Doesn't Display Scores

Hi Max,

In your code on the following line (line 195 in the forum post but doubtfully 195 in your actual code), please run about 5-10 tests using actual integer numbers in place of the “highScore” variable. I need to ensure that this isn’t somehow an issue that your code doesn’t know what “highScore” actually is and thus is submitting nil to GC.

[lua]

    localPlayerScore = { category = “spin.leaderboard”, value = highScore },

[/lua]

So, run a few tests using numbers like 10, 50, 100, 1000, 10000, etc. for the “value” key.

Brent

@brett

I tested it 8 times with all the numbers you said.  Still no scores.  Any ideas?

Hi Max,

Is the app even reaching that point in the code? Does the call even get made to “gameNetwork.request( “setHighScore”, … )”? Also, please go create a new leaderboard and eliminate the previous one (start fresh).

Brent

The code is incredibly hard to read since there are no indents, and there is a lot of unrelated code, but no where do I see “loggedIntoGC” defined or set to true anywhere, so I would guess that the code after line 191 is not be executed.

Below is what the leaderboard displays in my game:

Hi Max,

We probably can’t help you much without seeing your code on how you’re submitting scores. There are too many factors/variables involved with GC to know what’s happening without seeing some details.

Best regards,

Brent

@brent 

Below I am going to attach the code where I submit scores:

[lua] --remove status bar

display.setStatusBar(display.HiddenStatusBar)

–require modules

local storyboard = require “storyboard”

local scene = storyboard.newScene()

local game = require “game”

local gameNetwork = require “gameNetwork” 

local chartboost = require “plugin.chartboost”

local ads = require “ads”

local playagain

local playagainTxt

local leaderBoardIcon

local leaderBoardTxt

local restoreIcon

local restoreIconTxt

local facebookIcon

local reviewIcon

local star

local muteIcon 

local mute

–make play again button work

local function playagainBtn(event)

if (event.phase == “began”) then

audio.stop()

storyboard.removeScene( “gameover” )

storyboard.gotoScene( “menu” )

end

end

–make leaderboard button work

local function leaderBoardBtn(event)

if (event.phase == “began”) then

gameNetwork.show( “leaderboards”, { leaderboard = {category= “spin.leaderboard”, timeScope = “Week” } } )

end

end

–make restore button work

local function restoreBtn(event)

if (event.phase == “began”) then

store.restore()

end

end

–make facebook button work

local function facebookBtn(event)

if (event.phase == “began”) then

if system.openURL(“fb://profile/813278858755104”) then

system.openURL(“https://www.facebook.com/SpinAppGame”) 

print(“facebook worked!”)

end

end

end

–make review button work

local function reveiwBtn(event)

if (event.phase == “began”) then

system.openURL( “https://itunes.apple.com/us/app/spin!!!/id997123453?ls=1&mt=8” )

–fill in XXXXXXX as app id for review page

print(“review button worked!”)

end

end

–make mute button work

local function muteBtn(event)

if (event.numTaps == 1) then

audio.stop()

elseif (event.numTaps == 2) then

audio.play(menuSoundEffect)

print(“mute worked!”)

end

end

–menu sound effect

local menuSoundEffect = audio.loadStream(“quirk-tone.mp3”)

–create scene

function scene:createScene( event )

local group = self.view

–database tracker

local saveValue = function( strFilename, strValue)

–specified value to specified file

local theFile = strFilename

local theValue = strValue

local path = system.pathForFile( theFile, system.DocumentsDirectory )

–io.open opens a file at path. returns nil if no file found

local file = io.open( path, “w+” )

if file then

–write game distance to the text file

file:write( theValue )

io.close( file )

end

end

local loadValue = function( strFilename )

–will load specified file, or create a new file if it doesn’t exist

local theFile = strFilename

local path = system.pathForFile( theFile, system.DocumentsDirectory )

–io.open opens a file at path. returns nil if no file found

local file = io.open( path, “r” )

if file then

–read ALL contents of file into a string 

local contents = file:read( “*a” )

io.close( file )

return contents

else

–create file because it doesn’t exist yet

file = io.open( path, “w” )

file:write( “0” )

io.close( file )

return “0”

end

end

–database to hold user’s score

local highScoreFilename = “highScore.text”

local loadedhighScore = 

loadValue( highScoreFilename )

local highScore = tonumber( loadedhighScore )

–database to hold user’s score

local currentScoreFilename = “currentScore.text”

local loadedcurrentScore = 

loadValue( currentScoreFilename )

local currentScore = tonumber( loadedcurrentScore )

–colors in game

local colors = { “red”, “green”, “purple”, “yellow” }

local colorValues = {

red = {1, 0, 0},

yellow = {1, 1, 0},

purple = {.5, 0, .5},

green = {0, 1, 0}

}

–create background

local bg = display.newRect( 150, 150, 1220, 840)

bg:setFillColor(.2, .8, 1)

group:insert(bg)

–gameover text

local gameoverTxt = display.newText(“GAME OVER!”, display.contentCenterX, display.contentCenterY - 200, “BebasNeueBold”, 70)

group:insert(gameoverTxt)

–background rectangle behind scores to give nice effect

local scoreRect = display.newRect(display.contentCenterX, display.contentCenterY - 20, 250, 300)

group:insert(scoreRect)

–show high score

local showHighScore = display.newText("High Score: "…tostring(highScore), display.contentCenterX, display.contentCenterY - 50, “BebasNeueBold”, 50)

–function to make text change color(effect)

local function changeColor()

local chooseColor = colors[math.random(4)]–make cool text effect with colors

showHighScore:setFillColor(unpack(colorValues[chooseColor]))

end

changeColor()

timer.performWithDelay( 200, changeColor, -1 )–initiate the function to change text color

group:insert(showHighScore)

–show current score

local showCurrentScore = display.newText("Score: "…tostring(currentScore), display.contentCenterX, display.contentCenterY - 115, “BebasNeueBold”, 50)

showCurrentScore:setFillColor(0, 0, 0)

group:insert(showCurrentScore)

–play again button

playagain = display.newRoundedRect(display.contentCenterX, display.contentCenterY + 25, 200, 50, 10)

playagain:setFillColor(1, 0, 0)

playagainTxt = display.newText(“PLAY AGAIN?”, display.contentCenterX, display.contentCenterY + 25, “BebasNeueBold”, 30)

–show leaderboard icon

leaderBoardIcon = display.newRoundedRect(display.contentCenterX, display.contentCenterY + 90, 200, 50, 10)

leaderBoardIcon:setFillColor(1, 0, 0)

leaderBoardTxt = display.newText(“LEADERBOARD”, display.contentCenterX, display.contentCenterY + 90, “BebasNeueBold”, 30)

–send high score to game center

if (loggedIntoGC == true) then

print(“logged into game center”)

gameNetwork.request( “setHighScore”,

    {

        localPlayerScore = { category = “spin.leaderboard”, value = highScore },

        listener = requestCallback

    }

)

else

print(“NOT logged into game center”)

end

–add restore IAP button

restoreIcon = display.newRoundedRect(display.contentCenterX, display.contentCenterY + 158, 150, 30, 10)

restoreIcon:setFillColor(0, 1, 0)

–restore icon text

restoreIconTxt = display.newText(“Restore Purchases”, display.contentCenterX, display.contentCenterY + 158, “BebasNeueBold”, 20)

–create facebook icon

facebookIcon = display.newImage( “FB-f-Logo__blue_114.png” )

facebookIcon.x = display.contentCenterX - 100; facebookIcon.y = display.contentCenterY + 206

facebookIcon:scale(.5, .5)

print(“create facebook icon”)

–review app icon

reviewIcon = display.newRoundedRect(display.contentCenterX, display.contentCenterY + 206, 58, 60, 5) 

reviewIcon:setFillColor(.99, .6, .4)

star = display.newImage( “imageedit_1_3872267622.gif” )

star.x = display.contentCenterX; star.y = display.contentCenterY + 206

star:scale(.25, .25)

print(“create review app icon”)

–mute button icon

muteIcon = display.newRoundedRect(display.contentCenterX + 100, display.contentCenterY + 206, 58, 60, 5)

mute = display.newImage( “imageedit_1_8962693955.gif” )

mute.x = display.contentCenterX + 100; mute.y = display.contentCenterY + 206

mute:scale(.25, .25)

print(“create mute icon”)

print(“working test 1”)

print(chartboost.hasCachedRewardedVideo())

–create random number to decide if rewarded ad should be shown

local randomNumber = math.random(3)

print(randomNumber)

–show the reward video ad for user to gain a ‘continue game token’ based on randomNumber

local function showRewardedAd()

if (randomNumber == 2 and chartboost.hasCachedRewardedVideo() == true) then

chartboost.hasCachedRewardedVideo()–see if ad has been cached

chartboost.show( “rewardedVideo” )–show the rewarded ad

playagain:removeEventListener( “touch”, playagainBtn )–remove play again listener

print(“play again event listener removed”)

leaderBoardIcon:removeEventListener( “touch”, leaderBoardBtn )–remove leader board listener

print(“leader board event listener removed”) 

restoreIcon:removeEventListener( “touch”, restoreBtn )

print(“removed restore event listener”)

restoreIcon.alpha = 0

restoreIconTxt.alpha = 0

facebookIcon.alpha = 0

reviewIcon.alpha = 0

star.alpha = 0

muteIcon.alpha = 0

mute.alpha = 0

facebookIcon:removeEventListener( “touch”, facebookBtn )

reviewIcon:removeEventListener( “touch”, reveiwBtn )

muteIcon:removeEventListener( “tap”, muteBtn )

print(“all dislay objects removed!”)

print(“all listeners removed!”)

else

–continue as normal

end

end

showRewardedAd()

group:insert(playagain)

group:insert(playagainTxt)

group:insert(leaderBoardIcon)

group:insert(leaderBoardTxt)

group:insert(restoreIcon)

group:insert(restoreIconTxt)

group:insert(facebookIcon)

group:insert(reviewIcon)

group:insert(star)

group:insert(muteIcon)

group:insert(mute)

end

–enter scene

function scene:enterScene( event )

local group = self.view

playagain:addEventListener( “touch”, playagainBtn )

leaderBoardIcon:addEventListener( “touch”, leaderBoardBtn )

restoreIcon:addEventListener( “touch”, restoreBtn )

facebookIcon:addEventListener( “touch”, facebookBtn )

reviewIcon:addEventListener( “touch”, reveiwBtn )

muteIcon:addEventListener( “tap”, muteBtn )

ads.hide()

end

–exit scene

function scene:exitScene( event )

local group = self.view

end

–destroy scene

function scene:destroyScene( event )

local group = self.view

end

scene:addEventListener( “createScene”, scene)

scene:addEventListener( “enterScene”, scene)

scene:addEventListener( “exitScene”, scene)

scene:addEventListener( “destroyScene”, scene)

return scene [/lua]

Anybody have any help to offer? REALLY STUCK!

It would really help if your code was properly formatted.  It’s really hard to read when all lines are flush against the left edge.  See: https://coronalabs.com/blog/2015/06/09/tutorial-the-value-of-well-formatted-code/

Also, we don’t need to see your entire code either. We need to see where you’re initializing and logging into GameCenter and where you’re setting the score.

Is this a production app? or are you testing on a device? 

Does it say anything about *sandbox* anywhere?

What type of provisioning profile are you using?

Are you using your regular gameCenter account or a testing account?

Are you getting any errors or relevant messages in your device’s console log?

@Rob 

Thanks for your response!

This is an app that is currently on the iOS App Store. I have turned *sandbox* on.  When I launch the app it says my Game Center username and it says that I am signed in. Below my username it says **sandbox**.  I am using my app store distribution provision file.  I am using my regular Game Center.  I will check for errors in my device console when I get home.  However, it seems as GC is working fine up until I click the leaderboard and it says “no scores”. Thanks!

-Max

Hi Max,

One thing I’ve seen in the past… time and time again… is that developers attempt to submit “high scores” to GC without having properly set up what a “high score” actually is within iTunes Connect. In other words, they keep trying to submit high scores, but those scores are not actually “higher” than any previous score submitted, so GC simply tosses it out and ignores the call. Then the developer goes in circles trying to figure out why, but at the core, it’s that they simply did not submit a higher score, so nothing happens… in these cases, it has absolutely nothing to do with their code (in Corona), but simply that they didn’t not properly configure the leaderboard properly in iTunes Connect.

Now, this might not be your issue, but please check that carefully, because I’ve seen it happen over and over in the past to other developers, and simply fixing that makes everything work as expected. Remember to carefully check the leaderboard setup, including the sorting order (low to high, or high to low), etc.

Also remember that scores can take some time to get updated to GC. It doesn’t necessarily happen instantaneously.

Take care,

Brent

@brent 

Sadly all is setup… 

Below is an image of my iTunes connect GC area. 

If you are using a version of your app signed with a distribution for the store profile, it will not talk to the sandbox. That’s only for development profiles.

You need to go to the GameCenter app and logout of your test account, then run your app, login with an AppleID that you use in production and see if things work for you.

Rob

@rob

Did everything you said and still no scores… any other advice?

Did you ever have it working with the Sandbox?

@rob

Yes! it was working perfectly in sandbox before it wen’t live! Now it won’t display scores…

Hi Max,

In your code on the following line (line 195 in the forum post but doubtfully 195 in your actual code), please run about 5-10 tests using actual integer numbers in place of the “highScore” variable. I need to ensure that this isn’t somehow an issue that your code doesn’t know what “highScore” actually is and thus is submitting nil to GC.

[lua]

    localPlayerScore = { category = “spin.leaderboard”, value = highScore },

[/lua]

So, run a few tests using numbers like 10, 50, 100, 1000, 10000, etc. for the “value” key.

Brent

@brett

I tested it 8 times with all the numbers you said.  Still no scores.  Any ideas?

Hi Max,

Is the app even reaching that point in the code? Does the call even get made to “gameNetwork.request( “setHighScore”, … )”? Also, please go create a new leaderboard and eliminate the previous one (start fresh).

Brent

The code is incredibly hard to read since there are no indents, and there is a lot of unrelated code, but no where do I see “loggedIntoGC” defined or set to true anywhere, so I would guess that the code after line 191 is not be executed.