GPGS Help needed!

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.

Hi @amdriod95,

The first advice I have is that you don’t use a global declaration for “gameNetwork”. That alone could be causing core communication problems within the plugin between each of your scenes. In 99.9% of cases, using globals is awful and unnecessary.

Brent

okay so I will have to copy the code in main.lua to every scene where I will be using the leaderboard? 

I have changed it to local and I have copied the main.lua google play code to evey scene where I am using it but still no sucess still the same output

It’s probably not that simple. I recommend this:

In “main.lua”, reference GPGS under a local namespace:

[lua]

local gameNetwork = require( “gameNetwork” )

[/lua]

Also do your initialization tasks in “main.lua”.

In other scenes, do the same “local require()” of “gameNetwork” as shown above.

okay let me try to just intialize in every scene. I will be posting back in 2 mins. Please keep an eye I need to get this done. 

In main.lua I simple have a few forward reference setup and goto scene 

nope, still the same problem :confused:

I will probably need to see your updated code.

Also, can you please take out the Apple Game Center stuff for the moment? It’s making it more difficult to debug with that in place…

okay… here is my main.lua:

local gameNetwork = require( "gameNetwork" ) local playerName local function loadLocalPlayerCallback( event ) playerName = event.data.alias -- YOU DO NOT DEFINE THE FOLLOWING FUNCTION ANYWHERE; THAT IS A PROBLEM TO FIX --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() gameNetwork.init( "google", gpgsInitCallback ) 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 gameNetwork.request("login", { userInitiated = false }) end return true end Runtime:addEventListener( "system", systemEvents )

here is my menu.lua which has the button to show the leaderboard:

local gameNetwork = require( "gameNetwork" ) local function leadertapd(event) -- DO YOU EVEN SEE THIS SHOWN IN THE CONSOLE??? print("Leaderboard Tapped") -- FOR TESTING, COMMENT OUT ANYTHING ELSE UNRELATED    --audio.play(btn)    --audio.pause(menuMusic)    --ads.hide("banner", {appId=bannerAppID }) -- YOU SHOULD PROBABLY HANDLE CONNECTION ISSUES IN main.lua, NOT HERE. -- IF THE USER IS NOT CONNECTED, MAKE THEM CONNECT BEFORE EVER COMING TO THIS MODULE    --[[if gameNetwork.request("isConnected")  then       local function showLeaderboards( event )       gameNetwork.show( "leaderboards" )       return true end    else       gameNetwork.request("login", { listener = loginListener, userInitiated = true })       local function showLeaderboards( event )     if ( system.getInfo("platformName") == "Android" ) then       gameNetwork.show( "leaderboards" )     else       gameNetwork.show( "leaderboards", { leaderboard = {timeScope="AllTime"} } )     end     return true end        end--]] gameNetwork.show( "leaderboards" ) end          local leaderboard= widget.newButton {defaultFile = "BG.png", onRelease= leadertapd} leaderboard.x=centerX-4 leaderboard.y= centerY-10 -- YOU SHOULD NOT SET WIDGET BUTTON WIDTH/HEIGHT AFTER CREATION (BAD PRACTICE) leaderboard.width = 147 leaderboard.height=50 leaderboard.alpha=0.01 sceneGroup:insert(leaderboard)

here is my gameOver.Lua which updates the score at the end of the game:

local gameNetwork = require( "gameNetwork" ) --===============UPDATING LEADERBOARD==================================== 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 -- BIG PROBLEM: YOU ARE NOT SPECIFYING AN ACTUAL LEADERBOARD ID -- HOW DOES GPGS KNOW WHAT LEADERBOARD TO UPDATE??? local myCategory ="my leaderboard id here" gameNetwork.request( "setHighScore", { localPlayerScore = { category=myCategory, value=tonumber(score) }, listener = postScoreSubmit } ) --==============================ENDING LEADERBOARD==================================

I’ve modified your code and added some comments. Take a look and ask further questions…

I have modified the code acordingly but still no luck. and yes I do see the print statement Leaderboard Tapped shown on the console.

and I do have my leaderboad id here 

local myCategory ="my leaderboard id here"

in my actual code. I just replaced it here

But you say that it does allow you to log in to GPGS?

If so, let’s try doing this all within “main.lua” for testing. Add a few lines to your “loadLocalPlayerCallback()” function as follows…

[lua]

local function loadLocalPlayerCallback( event )

   playerName = event.data.alias

   – YOU DO NOT DEFINE THE FOLLOWING FUNCTION ANYWHERE; THAT IS A PROBLEM TO FIX

   --saveSettings()  --save player data locally using your own “saveSettings()” function

   – DO YOU SEE THIS IN THE CONSOLE?

   print( “IT IS REACHING HERE…” )

   gameNetwork.show( “leaderboards” )

end

[/lua]

yes, I said “It ask me to login and sometime even shows the screen where it asks for users the permission to access the profile and stuff”

it did ask me a few times before but its not asking me now… even when it logged in I coudnt open the leaderboard.

I have tried your code I cannot see iT IS REACHING HERE in the debug mood. ( just to add on I doo see the google play services logo pop up and trying to login in but then it just goes away…this was hapening even before)

I have created a new key and signed using that my new apk and also updated the sha1 in the google developer account now I do get to login screen the 1st time and sign in, giving it the permission to access my profile but only once. I think it saves the prefernces so next time I do not have to login and it auto logs in. But I still cant get to show the leaderboard!

On this new test, did it ever reach that print() statement “IT IS REACHING HERE…”, even if only on the first login?

Please put some print() statements in all of the other listener functions as well: “gameNetworkSetup()”, “gpgsInitCallback()”, and “gameNetworkLoginCallback()”. Then, try to clear out the “preferences” or log out of GPGS entirely so you can start with a clean plate. Then test and see which of those functions is actually getting called.

By the way, why are you doing a “return true” from the “gameNetworkLoginCallback()” function? It shouldn’t matter that it’s there, but then, I see no reason for it being there either.

Is there a reason you’re calling login multiple times?

@Rob

not really, I was just trying to make it work that way as it wasn’t running with even single login attempt. Was just testing it out.

Thank you Corona Staff , I actually figured out the problem it wasn’t with corona it was with Google. When It asked me to enter sha1 key I did and it did proceeded and gave me Oauth certificate. but then as I was strugling to log on I went in to the developer section under credentials tab I clicked on the project and found that my sha1 key wasn’t saved their it was blank. So I again had to put in my sha1 key and now its up and working as it should.

Please check it and update the guide to setup gpgs as it will really be helpful for the new and old users

Hi @amdriod95,

The first advice I have is that you don’t use a global declaration for “gameNetwork”. That alone could be causing core communication problems within the plugin between each of your scenes. In 99.9% of cases, using globals is awful and unnecessary.

Brent

okay so I will have to copy the code in main.lua to every scene where I will be using the leaderboard?