I wish I had an answer for you. This is working as expected in my game. I wish Google didn’t make setting things up so difficult. I’m going to post the settings for my game along with some notes:
First my build.settings “android” section:
android = { googlePlayGamesAppId = "249XXXXXXX34", -- this has to match what is online facebookAppId = "16XXXXXXXXXXXX61", usesPermissions = { "com.android.vending.BILLING", "com.android.vending.CHECK\_LICENSE", "android.permission.INTERNET", "android.permission.VIBRATE", "android.permission.WRITE\_EXTERNAL\_STORAGE", "android.permission.ACCESS\_NETWORK\_STATE", -- needed for the vungle plugin }, supportsScreens = { resizeableActivity = false, smallScreens = true, normalScreens = true, largeScreens = true, xlargeScreens = true, }, },
Go to the Game Services tab and find your game there:
Click on your game to get the value for googlePlayGamesAppId. Even though it looks like a number, make it a string!
Scroll to the bottom and make sure you have green checkmarks here:
Check on the linked app section and make sure your real game is linked. Both are likely sharing similar names.
Make sure you have a leaderboard added and published.
Finally, make sure you have no “triangle” “todo” logos here:
Then follow the tutorial on adding leaderboards to your app. My code will be a little different than the tutorial (but the tutorial was based on this and made more generic).
myData.gpgs = nil print("platform: ", myData.platform, system.getInfo("environment")) if "android" == myData.platform and "simulator" ~= system.getInfo("environment") then print("requiring GPGS") myData.gpgs = require("plugin.gpgs.v2") end local function gpgsLoginListener( event ) print("\*\*\* gpgsLoginListener \*\*\*") print( json.prettify( event ) ) if not event.isError then if ( event.name == "login" ) then -- Successful login event myData.isGameNetworkingLoggedIn = true print("I think isConnected() is", myData.gpgs.isConnected()) end end end if myData.gpgs then print("Initializing GPGS") --myData.gpgs.init( gpgsInitListener ) myData.gpgs.login( { userInitiated=true, listener=gpgsLoginListener } ) end
For testing purposes, I added a button to my UI to set a high score. It’s hard to test this through normal game play because getting a new high score is tough.
local function gcSubmitScoreListener() print("submitted") end local gpgsSetHighScoreButton = widget.newButton({ label = "Set High Score", onRelease = function( event ) myData.settings.highScore = myData.settings.highScore + 100000 myData.gpgs.leaderboards.submit({ leaderboardId = "CgkXXXXXXXXXXXXQBg", score = myData.settings.highScore, listener = gcSubmitScoreListener } ) end, }) sceneGroup:insert(gpgsSetHighScoreButton) gpgsSetHighScoreButton.x = display.contentWidth - 50 gpgsSetHighScoreButton.y = display.contentHeight - 20
Then to show the score:
local function gameNetworkingLeaderboards() print("\*\*\* gameNetworking leaderboards \*\*\*") if myData.gameNetwork then print("\*\*\* gameNetwork: attempting to call show leaderboard") myData.gameNetwork.show( "leaderboards", { leaderboard = { category = "com.myawesomegame.leaderboard" }, listener = showLeaders }) elseif myData.gameCenter then print("\*\*\* gameCenter leaderboards") myData.gameCenter.leaderboards.show("com.myawesomegame.leaderboard") elseif myData.gpgs then print("\*\*\* GPGS trying to show GPGS leaderboard", myData.gpgs.isConnected()) myData.gpgs.leaderboards.show( ) end end
This works for me. Did I get everything above? Who knows. Google keeps changing things and making it hard to find all the settings.
Can you copy/paste this code? Not a chance because you’re likely not using the same faux globals table I’m using. My ID’s have been masked. You likely have named functions differently.
But this works.