Cannot submit game center score

Hi There,

I updated to the latest public release of corona and it appears that I cannot submit the scores to the game center anymore - I already modified the settings file in order to get the gamenetwork plugin, so it shouldn’t be that.

When I load the app, I see the usual game center login screen, but every time I attempt to access the leaderboards, I do not get a response.

The system logs - from the ios simulator indicates the following:

Dec  8 20:20:08 unknown-a8-86-dd-b0-02-13.home exampleapp[20516]: Runtime error
    ?:0: attempt to index field ‘Leaderboard’ (a nil value)
    stack traceback:
        ?: in function <?:37>
        ?: in function ‘dispatchEvent’
        ?: in function ‘onRelease’
        ?: in function <?:31>
        (tail call): ?
        ?: in function <?:498>
        ?: in function <?:221>
 

Any help will be much appreciated.

Thanks

Hi @j_wbrown,

Can you please post your code where you attempt to handle this action/event?

Thanks,

Brent

Hi Brent, 

Sure. 

Logic from main.lua 


[lua]

local leaderboardiOSId = “example_world_rankings”

local leaderboardAndroidId = “AbCDeFGHiJkLm”

local leaderboardAmazonId = “world_rankings”

if (leaderboardiOSId and leaderboardAndroidId) then

local gc = require( “libs.gc” )

gc.init({

iOS=leaderboardiOSId,

android=leaderboardAndroidId,

amazon=leaderboardAmazonId,

isAmazon=isAmazon

})

end

[/lua]

libs.gc - libs/gc.lua


[lua]

local gameNetwork = require “gameNetwork”

local helper = require(“libs.helper”)

local loggedIntoGC = false

local androidLeaderboardId = “”

local iOSLeaderboardId = “”

local amazonLeaderboardId = “”

local function initCallback( event )

    – “showSignIn” is only available on iOS 6+

    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.

        – For the iOS 6.0 landscape orientation bug, this is an opportunity to remove native objects so they won’t rotate.

        – This is type “init” for all versions of Game Center.

    elseif event.data then

        loggedIntoGC = true

    end

end

local function onSystemEvent( event ) 

    if event.type == “applicationStart” then

        if helper.isAndroid then

            gameNetwork.init( “google”, initCallback )

            gameNetwork.request(“login”,{userInitiated = true})

        else

            gameNetwork.init( “gamecenter”, initCallback )

        end

        return true

    end

end

–[[example

Runtime:dispatchEvent({name=“gc”, cmd=“setHighScore”, value=25})

Runtime:dispatchEvent({name=“gc”, cmd=“showLeaderboard”})

]]

local function onGameCenterEvent(event)

    if event.cmd == “showLeaderboard” then

        if (gamecircle) then

            gamecircle.Leaderboard.OpenOverlay(amazonLeaderboardId)

        else

            gameNetwork.show( “leaderboards”, { leaderboard = {timeScope=“Week”}, listener=onGameNetworkPopupDismissed } )

        end

    elseif(event.cmd == “setHighScore”) then

        if (gamecircle) then

            gamecircle.Leaderboard.SubmitScore(amazonLeaderboardId, event.value)

        else

            local category = iOSLeaderboardId

            if (helper.isAndroid) then category = androidLeaderboardId end

            gameNetwork.request( “setHighScore”, {

                localPlayerScore = { category = category, value = event.value },

                listener = onGameNetworkRequestResult,

            })

        end

    end

end

local M = {};

function M.init(params)

    iOSLeaderboardId = params.iOS or “”

    androidLeaderboardId = params.android or “”

    amazonLeaderboardId = params.amazon or “”

    if params.isAmazon then

        gamecircle = require(“plugin.gamecircle”)

        gamecircle.Init(false, true, false) – false true false means - achievements, leaderboards, whispersync

    end

    Runtime:addEventListener( “system”, onSystemEvent )

    Runtime:addEventListener( “gc”,     onGameCenterEvent)

end

return M;

[/lua]

Settings file - XXXX replacing real Ids for privacy reasons


[lua]

settings = {

    orientation =

    {

        default = “landscapeLeft”,

        supported =

        {

          “landscapeRight”,

        },

    },

    android = {

        usesPermissions = {

                ‘android.permission.INTERNET’,

                ‘android.permission.ACCESS_NETWORK_STATE’,

                “android.permission.ACCESS_WIFI_STATE”,

                “android.permission.READ_PHONE_STATE”

        },

        googlePlayGamesAppId = “XXXXXXXXXXXX”, – Your Google Play Games App Id

    },

    plugins =

    {

        [“CoronaProvider.ads.admob”] =

        {

            publisherId = “com.coronalabs”

        },

        [“plugin.google.play.services”] =

        {

            publisherId = “com.coronalabs”,

            supportedPlatforms = { android = true }

        },

        [“CoronaProvider.gameNetwork.google”] = {

            publisherId = “com.coronalabs”,

            supportedPlatforms = { android = true }

        },

        [“facebook”] = {

            publisherId = “com.coronalabs”,

        },

        [“CoronaProvider.analytics.flurry”] =

        {

        publisherId = “com.coronalabs”,

        },

        [“CoronaProvider.gameNetwork.apple”] =

        {

            publisherId = “com.coronalabs”,

            supportedPlatforms = { iphone=true, [“iphone-sim”]=true },

        },

         [“plugin.gamecircle”] =

        {

            – required

            publisherId = “COM_INNOVATIVELEISURE”,

            supportedPlatforms = { [“android-kindle”] = true },

        },

    },

    iphone = {

        plist = {

            CFBundleIconFiles = {

                    “Icon.png”, 

                    “Icon@2x.png”, 

                    “Icon-72.png”, 

                    “Icon-72@2x.png”,

                    “Icon-Small-50.png” , 

                    “Icon-Small-50@2x.png” ,

                    “Icon-Small.png” , 

                    “Icon-Small@2x.png”,

                    “Icon-Small-40.png”,

                    “Icon-Small-40@2x.png”,

                    “Icon-76.png”,

                    “Icon-76@2x.png”,

                    “Icon-60.png”,

                    “Icon-60@2x.png”,

                    

            },

            UIAppFonts = 

            {

                “pixel.ttf”

            },

            CFBundleShortVersionString = “1.0”,

            UIApplicationExitsOnSuspend = false,

            FacebookAppID = ‘XXXXXXXXXXXX’,  --replace XXXXXXXXXX with your Facebook App ID

            CFBundleURLTypes = {

              {

                CFBundleURLSchemes = { ‘fbXXXXXXXXXXXX’, }

              }

            }

        },

    },

}

[/lua]

Thanks a lot for your help. 

Hi @j_wbrown,

I edited your post to include line numbers, but these won’t match your actual line numbers. Based on the error you’re getting, which line (in this post) seems to be causing it? It’s some reference to “Leaderboard” but I can’t be sure which…

Brent

Hi Brent,

Thanks for your help.

After checking through the code very very slowly, I was able to find the problem. Thanks a lot for the assistance.

Hi @j_wbrown,

Can you please post your code where you attempt to handle this action/event?

Thanks,

Brent

Hi Brent, 

Sure. 

Logic from main.lua 


[lua]

local leaderboardiOSId = “example_world_rankings”

local leaderboardAndroidId = “AbCDeFGHiJkLm”

local leaderboardAmazonId = “world_rankings”

if (leaderboardiOSId and leaderboardAndroidId) then

local gc = require( “libs.gc” )

gc.init({

iOS=leaderboardiOSId,

android=leaderboardAndroidId,

amazon=leaderboardAmazonId,

isAmazon=isAmazon

})

end

[/lua]

libs.gc - libs/gc.lua


[lua]

local gameNetwork = require “gameNetwork”

local helper = require(“libs.helper”)

local loggedIntoGC = false

local androidLeaderboardId = “”

local iOSLeaderboardId = “”

local amazonLeaderboardId = “”

local function initCallback( event )

    – “showSignIn” is only available on iOS 6+

    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.

        – For the iOS 6.0 landscape orientation bug, this is an opportunity to remove native objects so they won’t rotate.

        – This is type “init” for all versions of Game Center.

    elseif event.data then

        loggedIntoGC = true

    end

end

local function onSystemEvent( event ) 

    if event.type == “applicationStart” then

        if helper.isAndroid then

            gameNetwork.init( “google”, initCallback )

            gameNetwork.request(“login”,{userInitiated = true})

        else

            gameNetwork.init( “gamecenter”, initCallback )

        end

        return true

    end

end

–[[example

Runtime:dispatchEvent({name=“gc”, cmd=“setHighScore”, value=25})

Runtime:dispatchEvent({name=“gc”, cmd=“showLeaderboard”})

]]

local function onGameCenterEvent(event)

    if event.cmd == “showLeaderboard” then

        if (gamecircle) then

            gamecircle.Leaderboard.OpenOverlay(amazonLeaderboardId)

        else

            gameNetwork.show( “leaderboards”, { leaderboard = {timeScope=“Week”}, listener=onGameNetworkPopupDismissed } )

        end

    elseif(event.cmd == “setHighScore”) then

        if (gamecircle) then

            gamecircle.Leaderboard.SubmitScore(amazonLeaderboardId, event.value)

        else

            local category = iOSLeaderboardId

            if (helper.isAndroid) then category = androidLeaderboardId end

            gameNetwork.request( “setHighScore”, {

                localPlayerScore = { category = category, value = event.value },

                listener = onGameNetworkRequestResult,

            })

        end

    end

end

local M = {};

function M.init(params)

    iOSLeaderboardId = params.iOS or “”

    androidLeaderboardId = params.android or “”

    amazonLeaderboardId = params.amazon or “”

    if params.isAmazon then

        gamecircle = require(“plugin.gamecircle”)

        gamecircle.Init(false, true, false) – false true false means - achievements, leaderboards, whispersync

    end

    Runtime:addEventListener( “system”, onSystemEvent )

    Runtime:addEventListener( “gc”,     onGameCenterEvent)

end

return M;

[/lua]

Settings file - XXXX replacing real Ids for privacy reasons


[lua]

settings = {

    orientation =

    {

        default = “landscapeLeft”,

        supported =

        {

          “landscapeRight”,

        },

    },

    android = {

        usesPermissions = {

                ‘android.permission.INTERNET’,

                ‘android.permission.ACCESS_NETWORK_STATE’,

                “android.permission.ACCESS_WIFI_STATE”,

                “android.permission.READ_PHONE_STATE”

        },

        googlePlayGamesAppId = “XXXXXXXXXXXX”, – Your Google Play Games App Id

    },

    plugins =

    {

        [“CoronaProvider.ads.admob”] =

        {

            publisherId = “com.coronalabs”

        },

        [“plugin.google.play.services”] =

        {

            publisherId = “com.coronalabs”,

            supportedPlatforms = { android = true }

        },

        [“CoronaProvider.gameNetwork.google”] = {

            publisherId = “com.coronalabs”,

            supportedPlatforms = { android = true }

        },

        [“facebook”] = {

            publisherId = “com.coronalabs”,

        },

        [“CoronaProvider.analytics.flurry”] =

        {

        publisherId = “com.coronalabs”,

        },

        [“CoronaProvider.gameNetwork.apple”] =

        {

            publisherId = “com.coronalabs”,

            supportedPlatforms = { iphone=true, [“iphone-sim”]=true },

        },

         [“plugin.gamecircle”] =

        {

            – required

            publisherId = “COM_INNOVATIVELEISURE”,

            supportedPlatforms = { [“android-kindle”] = true },

        },

    },

    iphone = {

        plist = {

            CFBundleIconFiles = {

                    “Icon.png”, 

                    “Icon@2x.png”, 

                    “Icon-72.png”, 

                    “Icon-72@2x.png”,

                    “Icon-Small-50.png” , 

                    “Icon-Small-50@2x.png” ,

                    “Icon-Small.png” , 

                    “Icon-Small@2x.png”,

                    “Icon-Small-40.png”,

                    “Icon-Small-40@2x.png”,

                    “Icon-76.png”,

                    “Icon-76@2x.png”,

                    “Icon-60.png”,

                    “Icon-60@2x.png”,

                    

            },

            UIAppFonts = 

            {

                “pixel.ttf”

            },

            CFBundleShortVersionString = “1.0”,

            UIApplicationExitsOnSuspend = false,

            FacebookAppID = ‘XXXXXXXXXXXX’,  --replace XXXXXXXXXX with your Facebook App ID

            CFBundleURLTypes = {

              {

                CFBundleURLSchemes = { ‘fbXXXXXXXXXXXX’, }

              }

            }

        },

    },

}

[/lua]

Thanks a lot for your help. 

Hi @j_wbrown,

I edited your post to include line numbers, but these won’t match your actual line numbers. Based on the error you’re getting, which line (in this post) seems to be causing it? It’s some reference to “Leaderboard” but I can’t be sure which…

Brent

Hi Brent,

Thanks for your help.

After checking through the code very very slowly, I was able to find the problem. Thanks a lot for the assistance.