Google Play Games Services gpgs.snapshots questions

Hello!

I would like to implement certain parameters to save my game so that a user can access everything from any device. But I’m with this library a little fish.

Here are my questions:

  1. How could add any variable and upload it to the cloud with gpgs.snapshots.save () ?

  2. How can we retrieve the parameter with gpgs.snapshots.load () ?

I know the documentation is here: https://docs.coronalabs.com/plugin/gpgs/index.html#settings

But there is not much information.

Anyone who has used or have any idea of the code to implement?

Thank you!

Jorge

Hi. For general workflow you can follow official docs and examples by Google. Like this
https://developers.google.com/games/services/android/savedgames
Or this
https://www.youtube.com/watch?v=iHc2RBZs5T0

First, you need to open/create a snapshot. Use gpgs.snapshots.open()

gpgs.snapshots.open({ filename = filename, create = true, listener = function(event) print('Open event:', json.prettify(event)) snapshotId = event.snapshotId end })

filename is any string, for example “save_slot_1”.
Save snapshotId for later use.

Then you need to get the actual snapshot object, with which you can interact.

local snapshot = gpgs.snapshots.getSnapshot(snapshotId)

Now you can write some data or read some data, depending on what you want - save or load.

-- Save snapshot.contents.write('New data inside the snapshot, this can be a JSON string') -- Load print(snapshot.contents.read()) -- returns previously saved data, if it's a JSON, you can decode it into a table.

After you modified data, you must tell the plugin to upload the snapshot to the Google’s server.

gpgs.snapshots.save({ snapshotId = snapshot.id, description = 'Save Slot ' .. snapshot.id, playedTime = '12151', progress = 150, image = {filename = 'images/snapshot.png'}, listener = function(event) print('Save event:', json.prettify(event)) end })

Here only snapshotId param is required, else is optional.

From that point the player can pick up another device, load that snapshot and retrieve the saved data.

I hope that helps. If you have any other questions - feel free to ask.

Thank you so much !

I will try this tutorial and I will come back with news.

Kind regards,

Jorge

Hi again,

I did all tutorial in my game however it doesn’t work.

I think the problem is that I need to configure the Google API Client before, right? I though it was embebbed in the plugin “plugin.gpgs”. I mean this: 

“Specify the Drive.SCOPE_APPFOLDER scope and Drive.API API when you create your GoogleApiClient

in  the tutorial:

https://developers.google.com/games/services/android/savedgames

Could you tell me if the problem is this one?

Thanks again !

Jorge

Hi again,

are you sure that gpgs.snapshots.open works fine? :

gpgs.snapshots.open({
    filename = filename,
    create = true,
    listener = function(event)
        print(‘Open event:’, json.prettify(event))
        snapshotId = event.snapshotId
    end
})

The device just ignores the code !!!

Regards

No one ? Ghost Forum :frowning:

jgaldeanol, in Game details on Google’s developer portal, do you have “Saved Games” option turned on?
f26f27b519a34c9e81cd4125e2cfe99f.png

of course !

jgaldeanol, another silly question, have you logged in in your app? gpgs.init() and gpgs.login()?
What gpgs.isConnected() returns in your code when you try to open a snapshot?

Lerg, firdt of all thanks so much to help me. It is not silly questions dont worry.

And yes, i Connect with gpgs plugin to Google Play Game, and i have configure leaderboard and achievements as well and all work fine.

But no the snapshots, I have seen an API option for my game inside Google develop console. Do I have to configure any thing by this way?

Thanks!

jgaldeanol, I’ve just tested it on my device and everything went fine. If the rest is working, snapshots should too.
Upload your code somewhere so I can look at it.

local snapshot function loadSavedGamesGPGS() print("START open ...") function abrirSnap(event) snapshotId = event.snapshotId snapshot = gpgs.snapshots.getSnapshot(snapshotId) end params = { filename = "save\_slot\_Gold", create = true, conflictPolicy = "manual", abrirSnap } gpgs.snapshots.open(params) print("END open ...") print(" snapshotId: " .. snapshot) end

And this is the device console: 

10-29 09:17:01.509 31466 31487 I Corona  : WARNING: licensing.init() was already called for google.

10-29 09:17:01.509 31466 31487 I Corona  : START open …

10-29 09:17:01.510 31466 31487 I Corona  : END open …

10-29 09:17:01.510 31466 31487 I Corona  : ERROR: Runtime error

10-29 09:17:01.510 31466 31487 I Corona  : ?:0: attempt to concatenate upvalue ‘?’ (a nil value)

10-29 09:17:01.510 31466 31487 I Corona  : stack traceback:

10-29 09:17:01.510 31466 31487 I Corona  :      ?: in function ‘loadSavedGamesGPGS’

10-29 09:17:01.510 31466 31487 I Corona  :      ?: in main chunk

10-29 09:17:01.511 31466 31487 I Corona  : systemEvent applicationStart

I am completeley desesperate. I have put on the Saved Game in my Google Develop console but do I need to configure any thing more there ? I think when I use open() do not communicate with the server …

Regards

First of all, global functions are dangerous, they lead to hard to debug errors. Use “local” keyword for them when you can.

Secondly, remove the last print statement, snapshot variable is nil there.

Thirdly, you don’t specify the listener. In your case it should be “listener = abrirSnap” instead of just “abrirSnap” in params table.

Then in the listener you can try to print out snapshot id.

Hi guys,

thanks for all Lerg. I realise what is my problem. I call gpgs.snapshots.open() too fast and gpgs.login is not connected yet. So I let the second instruction more time and, of course, it works.

But now I have another quetion and is : how can i put the optimal time to login first with google play game service and, after this, open the snapshots ? I don’t want to lose time with time.performWithDelay functions.

Thanks a lot !

gpgs.login() also has a listener, which is invoked when the connection is established. Open your snapshot from that listener.

Thank you so much mate !

Hi. For general workflow you can follow official docs and examples by Google. Like this
https://developers.google.com/games/services/android/savedgames
Or this
https://www.youtube.com/watch?v=iHc2RBZs5T0

First, you need to open/create a snapshot. Use gpgs.snapshots.open()

gpgs.snapshots.open({ filename = filename, create = true, listener = function(event) print('Open event:', json.prettify(event)) snapshotId = event.snapshotId end })

filename is any string, for example “save_slot_1”.
Save snapshotId for later use.

Then you need to get the actual snapshot object, with which you can interact.

local snapshot = gpgs.snapshots.getSnapshot(snapshotId)

Now you can write some data or read some data, depending on what you want - save or load.

-- Save snapshot.contents.write('New data inside the snapshot, this can be a JSON string') -- Load print(snapshot.contents.read()) -- returns previously saved data, if it's a JSON, you can decode it into a table.

After you modified data, you must tell the plugin to upload the snapshot to the Google’s server.

gpgs.snapshots.save({ snapshotId = snapshot.id, description = 'Save Slot ' .. snapshot.id, playedTime = '12151', progress = 150, image = {filename = 'images/snapshot.png'}, listener = function(event) print('Save event:', json.prettify(event)) end })

Here only snapshotId param is required, else is optional.

From that point the player can pick up another device, load that snapshot and retrieve the saved data.

I hope that helps. If you have any other questions - feel free to ask.

Thank you so much !

I will try this tutorial and I will come back with news.

Kind regards,

Jorge

Hi again,

I did all tutorial in my game however it doesn’t work.

I think the problem is that I need to configure the Google API Client before, right? I though it was embebbed in the plugin “plugin.gpgs”. I mean this: 

“Specify the Drive.SCOPE_APPFOLDER scope and Drive.API API when you create your GoogleApiClient

in  the tutorial:

https://developers.google.com/games/services/android/savedgames

Could you tell me if the problem is this one?

Thanks again !

Jorge

Hi again,

are you sure that gpgs.snapshots.open works fine? :

gpgs.snapshots.open({
    filename = filename,
    create = true,
    listener = function(event)
        print(‘Open event:’, json.prettify(event))
        snapshotId = event.snapshotId
    end
})

The device just ignores the code !!!

Regards