Any news related to gpgs version 2 plugin?
My tests have all been successful, but the code for snapshots that I was using doesn’t work and needed updated. I’m trying to see how other testers results are going as I’m not privy to those communications.
Rob
Same here Rob.
Snapshots code doesn’t work and community really need it.
If there is a change in code or a workaround to make it work could you share it here please?
Please keep us updated if any news arise!
I’m happy to share the snapshot code from my test app. Again, it’s purely test code and my old code-pre-change once worked with the old plugin, so I can’t say this will work with the V1 plugin or not.
local myTable = { play = 1 } local snapshotFilename = "snapshot1" local data = json.encode( myTable ) local function gpgsSnapshotOpenForReadListener( event ) print( "snapshot open event:", json.prettify(event) ) if not event.isError then --local data = event.snapshot.contents.read() local data = gpgs.snapshots.getSnapshot (event.snapshotId) native.showAlert('Snapshots', 'Reading was ' .. (event.isError and 'unsuccessful' or 'successful') .. ',', { 'OK'}) end end local function gpgsSnapshotAfterSaveListener( event ) native.showAlert('Snapshots', 'Saving was ' .. (event.isError and 'unsuccessful' or 'successful') .. '.', {'OK'}) end local function openSnapshot() print("Opening snapshot") gpgs.snapshots.open({ filename = snapshotFilename, listener = gpgsSnapshotOpenForReadListener }) end local function gpgsSnapshotOpenForSaveListener( event ) print("open for save listener", json.prettify( event )) if not event.isError then local snapContent = gpgs.snapshots.getSnapshot(event.snapshotId).contents snapContent.write(data) -- Write new data as a JSON string into the snapshot gpgs.snapshots.save({ snapshotId = event.snapshotId, description = 'Save slot ' .. snapshotFilename, listener = gpgsSnapshotAfterSaveListener }) end end local function saveSnapshot() print("saving snapshhot") gpgs.snapshots.open({ -- Open the save slot filename = snapshotFilename, create = true, -- Create the snapshot if it's not found listener = gpgsSnapshotOpenForSaveListener }) end
There are still some issues we are working on with the testers so even if you managed to get access to the plugin when it was inadvertently made available, I still wouldn’t release against the V2 plugin until we say it’s ready.
Rob
I had this for gpgs version 1 and used to work (now it’s broken) like charm.
https://forums.coronalabs.com/topic/67896-how-to-implement-gpgs-plugin/
I can see the changes in your code but it would be better to make it work exactly as version 1.
Any chance for ETA? Days? Weeks?
This is tough to answer because “weeks” could mean anywhere between 2-8 weeks and I don’t think it will be anywhere in the 4-8 week range, but if I say “days”, in particular with the weekend in the way, it would set your expectations that it could be as early Monday or Tuesday and I don’t think that’s realistic either.
Have you tried the code above with the V1 plugin?
Rob
I don’t know why the code from the link in my previous post stopped working the last weeks but I tried your code with ver1 plugin.
Did some changes and now I’m able to open snapshots.
Trying to do the same for saving snapshots too.
–edit
Saving works too, thnx Rob!
@Rob, any idea when this will be out of Beta?
FYI, my new app has about 500 installs with no ANRs and no crashes. You and your team deserves big time kudos!
@troylyndon we announced it last week. It’s not really in beta and should be a drop-in replacement. However, there are some reports on another thread of it not working. I would invite you to give it a try and help us identify if there are problems. Just make sure to test it before making a public release.
Rob
I am using gpgs v1. My snapshot functionality used to work before now it is not working anymore. No code changes were made from my side. Only the corona version was changed.
I have tried gpgs v2 as a drop in replacement but the login pop up doesn’t even show and I can’t see any errors also so just reverted back to v1 again.
Currently building with 2018.3397.
Can you compare your snapshot code to this?
local myTable = { play = 1 } local snapshotFilename = "snapshot1" local data = json.encode( myTable ) local function gpgsSnapshotOpenForReadListener( event ) print( "snapshot open event:", json.prettify(event) ) if not event.isError then local data = event.snapshot.contents.read() native.showAlert('Snapshots', 'Reading was ' .. (event.isError and 'unsuccessful' or 'successful') .. ',', { 'OK'}) end end local function gpgsSnapshotAfterSaveListener( event ) native.showAlert('Snapshots', 'Saving was ' .. (event.isError and 'unsuccessful' or 'successful') .. '.', {'OK'}) end function myData.openSnapshot() print("Opening snapshot") gpgs.snapshots.open({ filename = snapshotFilename, listener = gpgsSnapshotOpenForReadListener }) end local function gpgsSnapshotOpenForSaveListener( event ) print("open for save listener", json.prettify( event )) if not event.isError then event.snapshot.contents.write(data) -- Write new data as a JSON string into the snapshot gpgs.snapshots.save({ snapshot = event.snapshot, description = 'Save slot ' .. snapshotFilename, listener = gpgsSnapshotAfterSaveListener }) end end function myData.saveSnapshot() print("saving snapshhot") gpgs.snapshots.open({ -- Open the save slot filename = snapshotFilename, create = true, -- Create the snapshot if it's not found listener = gpgsSnapshotOpenForSaveListener }) end
Apparently, there were multiple ways to do snapshots.
Rob
Yes my snapshot code is very similar to your one. The only difference is that I don’t have myData.savesnapshot() as a separate function. I have used the code of this how to implement gpgs post.
During pre-launch test on developer console, one instance of an error was found, here is the message:
FATAL EXCEPTION: main Process: com.sheekore.games.sentioTapEmoji, PID: 12290 java.lang.NullPointerException: value == null at java.util.Hashtable.put(Hashtable.java:362) at plugin.gpgs.Utils.gameToHashtable(Utils.java:380) at plugin.gpgs.Utils.snapshotMetadataToHashtable(Utils.java:444) at plugin.gpgs.Snapshots$LoadSnapshotsResultCallback.onResult(Snapshots.java:412) at plugin.gpgs.Snapshots$LoadSnapshotsResultCallback.onResult(Snapshots.java:389) at com.google.android.gms.common.api.internal.BasePendingResult$CallbackHandler.handleMessage(Unknown Source) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5459) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
I don’t know where the snapshot code in that forum post originated, it almost looks like it’s your original code. The code I used to have wasn’t working either. The engineer who built the plugin provided me with the updated code which I tested with both V1 and V2 of the plugin.
I’ll share this with Engineering.
Rob
I have updated the snapshot code. I am trying gpgs.v2 plugin, but it seems I can’t login. gpgs.isConnected() is giving false always but event.phase in gpgsLoginListener function is saying ‘logged in’. The pop up that normally used to show in gpgs V1 is not showing here.
here is how I implemented the login functionality. With gpgs V1 it works but when I add v2, the login doesn’t work anymore. Are there any changes to be made?
local gpgs = require( "plugin.gpgs.v2" ) local function toggleGPGSToLogin( self, event ) if ( gpgs.isConnected() ) then gpgsLoggedOutButton.isVisible = false gpgsLoggedInButton.isVisible = true local tempGameData = loadsave.loadTable( "gameData.json" ) -- download snapshot local function gpgsSnapshotOpenForReadListener( event ) if not event.isError then -- local retrievedData = event.snapshot.contents.read() local retrievedData = gpgs.snapshots.getSnapshot (event.snapshotId) local gameData, pos, msg = json.decode( retrievedData ) if not gameData then toast.show('Decoding failed.' ..tostring(pos)..": "..tostring(msg) ) else if ( tempGameData.inGameAnalyticsTotalGamePlayed \< gameData.inGameAnalyticsTotalGamePlayed ) then -- save table from the gpgs server loadsave.saveTable( gameData, "gameData.json" ) else -- upload the offline gameplayed to GPGS server local gameData = loadsave.loadTable( "gameData.json" ) -- loading gameData from phone -- save snapshots local function gpgsSnapshotOpenForSaveListener( event ) if not event.isError then local snapContent = gpgs.snapshots.getSnapshot(event.snapshotId).contents snapContent.write( json.encode(gameData) ) -- Write new gameData as a JSON string into the snapshot gpgs.snapshots.save({ snapshotId = event.snapshotId, description = "Game scores", image = { filename = "EmojiCrushShare.png", baseDir = system.ResourceDirectory }, }) end end -- gpgsSnapshotOpenForSaveListener func END gpgs.snapshots.open({ -- Open the save slot filename = snapshotFileName, create = true, -- Create the snapshot if it's not found conflictPolicy = "most recently modified", listener = gpgsSnapshotOpenForSaveListener }) end -- (tempInGameAnalytics.totalGamePlayed \< inGameAnalytics.totalGamePlayed) conditional END end -- not inGameAnalytics conditional END end -- event.iserror conditional END end --gpgsSnapshotOpenForReadListener func END gpgs.snapshots.open({ filename = snapshotFileName, conflictPolicy = "most recently modified", listener = gpgsSnapshotOpenForReadListener }) end -- gpgs.isConnected() conditional END end -- toggleGPGSToLogin func END local function gpgsLoginListener( event ) gameData.gpgsDataUserPref = event.phase print ("gpgsLoginListener") print (event.phase) loadsave.saveTable( gameData, "gameData.json" ) toggleGPGSToLogin() if event.isError then toast.show("Sign in problem: Check network connection.") end -- event.isError conditional END end local function onGpgsLoginButtonTap( self, event ) print ("onGpgsLoginButtonTap") print (gpgs.isConnected()) if (gpgs.isConnected()) then --logout gpgs.logout() gameData.gpgsDataUserPref = "logged out" loadsave.saveTable( gameData, "gameData.json" ) gpgsLoggedOutButton.isVisible = true gpgsLoggedInButton.isVisible = false else --login gpgs.login( { userInitiated = true, listener = gpgsLoginListener } ) end -- login or logout conditional END return true end -- onGpgsLoginButtonTap func END gpgsLoggedInButton:addEventListener( "tap", onGpgsLoginButtonTap ) gpgsLoggedOutButton:addEventListener( "tap", onGpgsLoginButtonTap )
Our engineer is investigating. It’s really weird because when I use a game I’m working on, it works as expected. When I change the credentials to something new, .isConnected() fails reliably. This leads me to believe that the new library from Google is dependent on a setting in the Google Play Console which wasn’t required with the v1 plugin.
Rob
Can everyone here give it another try? We pushed a possible fix for the .isConnected() API today.
Thanks
Rob
I have built with 2018.3407
The login functionality is working,but now the achievements, leaderboards and snapshots are not working. even after log in. The default windows are not showing up for them.
Code for achievements and leaderboards funcitonality:
local function handleButton(event) if (event.target.id == "inGameLeaderboards" and event.phase == "ended") then if (gpgs.isConnected()) then gpgs.leaderboards.show() else gpgs.login( { userInitiated = true, listener = gpgsLoginListener } ) gpgs.leaderboards.show() end -- gpgs is connected check outer END elseif (event.target.id == "inGameAchievements" and event.phase == "ended") then if (gpgs.isConnected()) then gpgs.achievements.show() else gpgs.login( { userInitiated = true, listener = gpgsLoginListener } ) gpgs.achievements.show() end -- gpgs is connected check outer END end -- button conditional END end
Code for snapshots upload and download funcitonality:
local function handleButton (event) if (event.target.id == "cloudUpload" and event.phase == "ended") then -- save snapshots local function gpgsSnapshotOpenForSaveListener( event ) if not event.isError then local snapContent = gpgs.snapshots.getSnapshot(event.snapshotId).contents snapContent.write( json.encode(gameData) ) -- Write new gameData as a JSON string into the snapshot gpgs.snapshots.save({ snapshotId = event.snapshotId, description = "Game scores", image = { filename = "EmojiCrushShare.png", baseDir = system.ResourceDirectory }, }) end end -- gpgsSnapshotOpenForSaveListener func END if (gpgs.isConnected()) then gpgs.snapshots.open({ -- Open the save slot filename = snapshotFileName, create = true, -- Create the snapshot if it's not found conflictPolicy = "most recently modified", listener = gpgsSnapshotOpenForSaveListener }) gpgs.snapshots.load( {reload = true, }) gpgs.snapshots.show( {title = "Emoji Crush", disableAdd = false, disableDelete = false}) else gpgs.login( { userInitiated = true, listener = gpgsLoginListener } ) gpgs.snapshots.open({ -- Open the save slot filename = snapshotFileName, create = true, -- Create the snapshot if it's not found conflictPolicy = "most recently modified", listener = gpgsSnapshotOpenForSaveListener }) gpgs.snapshots.load( {reload = true, }) gpgs.snapshots.show( {title = "Emoji Crush", disableAdd = false, disableDelete = false}) end -- gpgs is connected check outer END elseif (event.target.id == "cloudDownload" and event.phase == "ended") then -- download snapshot local function gpgsSnapshotOpenForReadListener( event ) if not event.isError then local retrievedData = gpgs.snapshots.getSnapshot (event.snapshotId) local gameData, pos, msg = json.decode( retrievedData ) if not gameData then toast.show('Decoding failed.' ..tostring(pos)..": "..tostring(msg)) else loadsave.saveTable( gameData, "gameData.json" ) end else -- DO NOTHING end -- event.iserror conditional END end --gpgsSnapshotOpenForReadListener func END if (gpgs.isConnected()) then gpgs.snapshots.open({ filename = snapshotFileName, conflictPolicy = "most recently modified", listener = gpgsSnapshotOpenForReadListener }) gpgs.snapshots.load( {reload = true, }) gpgs.snapshots.show( {title = "Emoji Crush", disableAdd = false, disableDelete = false}) else gpgs.login( { userInitiated = true, listener = gpgsLoginListener } ) gpgs.snapshots.open({ filename = snapshotFileName, conflictPolicy = "most recently modified", listener = gpgsSnapshotOpenForReadListener }) gpgs.snapshots.load( {reload = true, }) gpgs.snapshots.show( {title = "Emoji Crush", disableAdd = false, disableDelete = false}) end -- gpgs.isconnected END end-- conditional END
Hi Rob,
I’ve just rebuilt the game and tested it here. I got the same results. Nothing happens when calling gpgs.leaderboards.show() or gpgs.achievements.show().
Br,
Cleverson
Please see my post here. https://forums.coronalabs.com/topic/73999-from-the-blog-new-google-play-games-services-plugin/page-2#entry390218
Let’s keep the conversation there!
Thanks
Rob