[GPGS] gpgs.snapshots.open doesn't work with saved games in Android ?

Hi all,

I am really desesperate because I am implementing gpgs in my game and I get correctly login Google Play games, archievements and leaderboards however it seems impossible to implement the snapshots.

This is my code: 

function loadSavedGamesGPGS()

    print(“START open …”)

    gpgs.snapshots.open({

    filename = “save_slot_G”,

    create = true,

    listener = function(event)

                       snapshotId = event.snapshotId

                    end

    })

    print(“END open …”)

    print(“START getSnapshot …”)

    snapshot = gpgs.snapshots.getSnapshot( snapshotId )

    print("snapshot: " … snapshot)

    print(“END getSnapshot …”)

end

When I connect my device to debug it, appears this log:

10-28 09:46:40.965 29877 29904 I Corona  : START open …

10-28 09:46:40.965 29877 29904 I Corona  : END open …

10-28 09:46:40.965 29877 29904 I Corona  : START getSnapshot …

10-28 09:46:40.965 29877 29904 I Corona  : ERROR: Runtime error

10-28 09:46:40.965 29877 29904 I Corona  : ?:0: attempt to concatenate global ‘snapshot’ (a nil value)

10-28 09:46:40.965 29877 29904 I Corona  : stack traceback:

10-28 09:46:40.965 29877 29904 I Corona  :      ?: in function ‘loadSavedGamesGPGS’

10-28 09:46:40.965 29877 29904 I Corona  :      ?: in main chunk

I am just wondering if gpgs.snapshots.open is ignored and if i am doing well. The configuration in Google develop console is correct with saved games and my permissions for android are: 

“android.permission.INTERNET”,

“com.android.vending.BILLING”,

“com.android.vending.CHECK_LICENSE”,

“android.permission.WRITE_EXTERNAL_STORAGE”,

I think open is not working, is there any place in google where I could see by UI all snapshots created ? 

Any advice ?

Thanks so much,

Jorge

Hi Jorge,

What I suspect is happening is that your snapshot is not yet “fully opened” by the time you attempt to call “getSnapshot” on its ID. Basically, it’s going like this:

  1. You call “open()” and it starts going to work opening it.

  2. Immediately after, as in literally the same runtime application frame, you call “getSnapshot()” using “snapshotId”, but that hasn’t resolved yet so it’s nil. Thus, the call fails and returns nil to the “snapshot” variable.

  3. You try to print() the value of the snapshot, but since it’s nil, you get a Lua concatenation error.

Basically, you should move your “getSnapshot” code up inside the completion listener function of the “open” call, so that GPGS has a fully opened and accessible snapshot to deal with.

Hope this helps,

Brent

It doesn’t work. Could you tell me if open is correct? I think that the problem is that open doesn’t work because the listener is never called, I don’t know why. Do I need to get gpgs.login first of all with a delay time ???

If I put this it fails too :

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

It never show at console " abrirSnap Activated"

I would highly suggest making 100% sure the user is logged in before you do anything else. Remember that services like GPGS are, obviously, sending/receiving data in the cloud, so there’s no guarantee that a call like login() will immediately (as in the same runtime frame) trigger the state for which you can use other calls.

Brent

Hi Brent,

it is correct !

Is there any good way to load all snapshots just after load gpgs.login(). The fastest way I mean.

Thanks a lot !

Jorge

Hi Jorge,

Good to hear it’s working now!

For loading snapshots, snapshots.load() loads all of them and gives you back an array of snapshots in the call’s listener as “event.snapshots”. From there, you can decide how to process them all.

https://docs.coronalabs.com/plugin/gpgs/snapshots/event/load/snapshots.html

Brent

Hi Jorge,

What I suspect is happening is that your snapshot is not yet “fully opened” by the time you attempt to call “getSnapshot” on its ID. Basically, it’s going like this:

  1. You call “open()” and it starts going to work opening it.

  2. Immediately after, as in literally the same runtime application frame, you call “getSnapshot()” using “snapshotId”, but that hasn’t resolved yet so it’s nil. Thus, the call fails and returns nil to the “snapshot” variable.

  3. You try to print() the value of the snapshot, but since it’s nil, you get a Lua concatenation error.

Basically, you should move your “getSnapshot” code up inside the completion listener function of the “open” call, so that GPGS has a fully opened and accessible snapshot to deal with.

Hope this helps,

Brent

It doesn’t work. Could you tell me if open is correct? I think that the problem is that open doesn’t work because the listener is never called, I don’t know why. Do I need to get gpgs.login first of all with a delay time ???

If I put this it fails too :

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

It never show at console " abrirSnap Activated"

I would highly suggest making 100% sure the user is logged in before you do anything else. Remember that services like GPGS are, obviously, sending/receiving data in the cloud, so there’s no guarantee that a call like login() will immediately (as in the same runtime frame) trigger the state for which you can use other calls.

Brent

Hi Brent,

it is correct !

Is there any good way to load all snapshots just after load gpgs.login(). The fastest way I mean.

Thanks a lot !

Jorge

Hi Jorge,

Good to hear it’s working now!

For loading snapshots, snapshots.load() loads all of them and gives you back an array of snapshots in the call’s listener as “event.snapshots”. From there, you can decide how to process them all.

https://docs.coronalabs.com/plugin/gpgs/snapshots/event/load/snapshots.html

Brent