I’ve been trying to implement google play game services in my app for 3 days now but no success. It ask me to login and sometime even shows the screen where it asks for users the permission to access the profile and stuff… But still I can’t get to show the leader board.
Whenever I tap the leader board nothing happens. I have even tried to do debug using adb console but using adb logcat Corona:v *:s but it does not show anything because this code shows stuff only related to corona I guess and so I have tried the other one adb logcat but it shows too many things too fast to even notice anything.
Also sometimes I do receive an error on my phone when I run this app that is because of the gpgs before that it was fine.
I’m going to explain and show each and every code I’ve put in related to gpgs. I need to get this as this is the only thing holding my app back from the play store.
-First, I created an account on google developer ,moved on to add a new application and also singed my app using the private key and got the sha1 key required.(my package name is also the same that I am using while making the buil)
-then I have gone to add game services and added the required information this game me an appID and leaderboard ID (I am not going to use achivements although I have them setup for this to work)
-GPGS are now published and on
Now, on corona side:
I have this code in my build settings:
settings = android = { googlePlayGamesAppId = "69113248265" -- (changed)--long App ID number (use yours!) }, plugins = { ["CoronaProvider.native.popup.social"] = { publisherId = "com.coronalabs" }, --key is the name passed to the Lua "require()" ["CoronaProvider.gameNetwork.google"] = { --required! publisherId = "com.coronalabs", }, ["plugin.google.play.services"] = { publisherId = "com.coronalabs" }, }, -- I have removed the non-relevant code and ignore the braces mistake here, I am just showing you the code related to gpgs I have added }
Now in my config.lua this is what I have:
application = { license = { google = { key = "SuZI9+p8MJcSidCOOEWqoZrm9Z1EiuzxOk6TQ/v+FfXnvWuzgMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmRuMWQnLjBObFbA7RPmMecQFCYl48d/u9iyeb5pQhXCA6LSI5xMB/NwTM/+YBUgncTQl19RB3WueL5XTaCBbv5436CxXQ5Wrnolm9Nx8gN0Zp1OtLVtpWRfcBu8GVsW+x/l+AO2HmKuvynXWz3KCVesCUSGLfFdArLIIAJAjYC0HJpgZOorUTeib5qEGRhr8E5LdLPj5jAqDoTWqCIKsf/VMQTcpNkRejnoW7GALmiJbbeQaWXZabFRgBcy52R7su6OH2ifki5fOKCJDfrrhD8N919j+CYF8ET8nwIDAQAB",}, },
In my main.lua this is what I have:
gameNetwork = require( "gameNetwork" ) local playerName local function loadLocalPlayerCallback( event ) playerName = event.data.alias saveSettings() --save player data locally using your own "saveSettings()" function end local function gameNetworkLoginCallback( event ) gameNetwork.request( "loadLocalPlayer", { listener=loadLocalPlayerCallback } ) return true end local function gpgsInitCallback( event ) gameNetwork.request( "login", { userInitiated=true, listener=gameNetworkLoginCallback } ) end local function gameNetworkSetup() if ( system.getInfo("platformName") == "Android" ) then gameNetwork.init( "google", gpgsInitCallback ) else gameNetwork.init( "gamecenter", gameNetworkLoginCallback ) end end ------HANDLE SYSTEM EVENTS------ local function systemEvents( event ) print("systemEvent " .. event.type) if ( event.type == "applicationSuspend" ) then print( "suspending..........................." ) elseif ( event.type == "applicationResume" ) then print( "resuming............................." ) elseif ( event.type == "applicationExit" ) then print( "exiting.............................." ) elseif ( event.type == "applicationStart" ) then gameNetworkSetup() --login to the network here end return true end Runtime:addEventListener( "system", systemEvents )
and In my menu.lua which is basically the main menu and the 1st screen I have a button and onrelease=the show leaderboard code. here is how it looks:
local function leadertapd(event) print("Leaderboard Tapped") audio.play(btn) audio.pause(menuMusic) ads.hide("banner", {appId=bannerAppID }) --===============SHWOING LEADER BOARD CODE================ local function showLeaderboards( event ) if ( system.getInfo("platformName") == "Android" ) then gameNetwork.show( "leaderboards" ) else gameNetwork.show( "leaderboards", { leaderboard = {timeScope="AllTime"} } ) end return true end --====================LEADERBOARD CODE ENDS HERE end local leaderboard= widget.newButton {defaultFile = "BG.png", onRelease= leadertapd} leaderboard.x=centerX-4 leaderboard.y= centerY-10 leaderboard.width = 147 leaderboard.height=50 leaderboard.alpha=0.01 sceneGroup:insert(leaderboard)
and in my gameOver.lua this is where the game ends and I want to update the users score. This is what I have here:
local function postScoreSubmit( event ) --whatever code you need following a score submission... return true end local myScore = 100 --for GPGS, reset "myCategory" to the string provided from the leaderboard setup in Google local myCategory ="tOQIEAIQvIBggfgr" -- this is where I have put in my leaderboard ID gameNetwork.request( "setHighScore", { localPlayerScore = { category=myCategory, value=tonumber(score) }, listener = postScoreSubmit } )
Please help me out with this. I have posted a several times about this but got no reply. I hope to get it solved asap thanks.
