Greetings, I’m working on my game and I want to integrate it with Google Play Game Center. I have one .lua file which has functions that are working with GPGC. This file looks like this:
----------------------------------------------------------------------------------------- -- -- gpgs\_manager.lua -- This class is used for Google Play Game Center ----------------------------------------------------------------------------------------- -- Your code here module(...,package.seeall); local gameNetwork=require("gameNetwork"); local loggedIntoGC = false local function initCallback(event) if not event.isError then loggedIntoGC = true userInitiated = false print("INIT CALLBACK SUCCESS"); else print("INIT CALLBACK ERROR"); print("Error Code: ", event.errorCode) end end local function loginListener(event1) -- Checks to see if there was an error with the login. if event1.isError then print("THERE IS SOME ERROR"); else print("SUCCESSFUL LOGIN"); loggedIntoGC = true; end end local function achievementRequestCallback(event) print("achievementRequestCallback"); end function returnGameNetworkState() return gameNetwork.request("isConnected"); end function logoutFromGameNetwork() gameNetwork.request("logout") end function loginToGameNetwork() -- Tries to login the user, if there is a problem then it will try to resolve it. eg. Show the log in screen. gameNetwork.request("login",{listener = loginListener,userInitiated = true}); end function initializeGPGC() gameNetwork.init("google",initCallback) end function unlockAchievement() myAchievement="CgkIstyY2-cKEAIQCA"; gameNetwork.request( "unlockAchievement",{achievement = { identifier=myAchievement, percentComplete=100, showsCompletionBanner=true },listener = achievementRequestCallback} ) end
In my mainmenu.lua file I have button that calls loginToGameNetwork() which successfully logs me into GPGS. But when I change screen and go to level screen(using director:changeScreen(“level”,“fade”)) my
session is lost. Every time I call function returnGameNetworkState() it returns me false.
Is there any way to save network session or is there some better way to do this?
Thanks in advance!