GPGS Snapshot Retrieval

So i have gpgs working in my current game and everything is fine i can save data to the server and when i check to make sure it’s there it is… but my problem is reading the data back. I opened the snapshot and then when i try to read the snapshot objects contents with object:read() i get nothing? What format is it in? I’ve tried everything i can think of and it’s not nil so i have no idea where the data is. It should be as simple as

local data = object:read()

Right? Or am I missing something? I even tried decoding it like it was a json.

Anyone have a solution to this?

Anyone? The documentation doesn’t specify what type of data the “payload” is. Is there somewhere else i can go for answers? These forums seem dead.

What specific API’s are you trying to use? I don’t see a :read() API under GPGS’s plugin docs.

Rob

https://docs.coronalabs.com/plugin/gpgs/snapshots/type/Snapshot/index.html

Under object.contents

It creates a snapshotcontents object and then you can read or modify the data

https://docs.coronalabs.com/plugin/gpgs/snapshots/type/SnapshotContents/index.html

But it never says what the “payload” is. I’ve tried everything but i can’t read the data i’ve saved.

Before you can call the .read() method, it’s expected that you would have already called the .write() method at some point. The API documentation says that .write() expects a string value.  No numbers, no tables, no booleans. Obviously you would like to store things other than strings like a table of data and that’s where the JSON library comes into play.

json.encode( someTable) returns a string that represents that table in a standard format. You can use the json.* library to convert the table to a string and then when reading convert it back to a table:

object.write( json.encode( yourTableToSave ) )

Then to get it back:

myTable = json.decode( object.read() )

Does that help?

Rob

Thanks! I’m sure this will lead me in the direction i need. I’ll update with my results when i get it finished.

Sigh…a capital letter…all this fuss over a capital letter. I was doing it right the whole time lol. Thanks for the response :slight_smile:

Hi 

I am a bit late to this topic. My question is that if  I already have a gameInfo.json can I directly use event.snapshot.contents.write( gameInfo.json ) ?

I am using local loadsave = require(" loadsave") by Rob Miracle to save my game data as gameInfo.json. 

The same JSON will work. The loadsave functionality hides your need to have access to the JSON file. You give it a table, you get a table. But I suppose you could either 

  1. read the saved file back in like load does and instead of converting it to a Lua table, just save the read data in it’s JSON form. JSON is just a big string that represents your table.

  2. Just use json.encode( yourTable ) as the value to GPGS.

  3. Modify your loadsave functions to also write the JSON string to GPGS at the same time it saves it to a local file.

Rob

@Rob. Thank you for the insight. I am going with option 2. Can you please have a look at this post (GPGS new plugin implementation basics) regarding the GPGS new plugin. I have implemented option 2 if you could please check whether it is correct or not.

 

Have you tried it?

Are you having problems?

Rob

@Rob

I haven’t tried testing it yet since I am having other issues with login. I have posted the code in another postsince it was not related to this post. If you could please have a look at there it would be a great help to me. 

Thank you :slight_smile:

Anyone? The documentation doesn’t specify what type of data the “payload” is. Is there somewhere else i can go for answers? These forums seem dead.

What specific API’s are you trying to use? I don’t see a :read() API under GPGS’s plugin docs.

Rob

https://docs.coronalabs.com/plugin/gpgs/snapshots/type/Snapshot/index.html

Under object.contents

It creates a snapshotcontents object and then you can read or modify the data

https://docs.coronalabs.com/plugin/gpgs/snapshots/type/SnapshotContents/index.html

But it never says what the “payload” is. I’ve tried everything but i can’t read the data i’ve saved.

Before you can call the .read() method, it’s expected that you would have already called the .write() method at some point. The API documentation says that .write() expects a string value.  No numbers, no tables, no booleans. Obviously you would like to store things other than strings like a table of data and that’s where the JSON library comes into play.

json.encode( someTable) returns a string that represents that table in a standard format. You can use the json.* library to convert the table to a string and then when reading convert it back to a table:

object.write( json.encode( yourTableToSave ) )

Then to get it back:

myTable = json.decode( object.read() )

Does that help?

Rob

Thanks! I’m sure this will lead me in the direction i need. I’ll update with my results when i get it finished.

Sigh…a capital letter…all this fuss over a capital letter. I was doing it right the whole time lol. Thanks for the response :slight_smile:

Hi 

I am a bit late to this topic. My question is that if  I already have a gameInfo.json can I directly use event.snapshot.contents.write( gameInfo.json ) ?

I am using local loadsave = require(" loadsave") by Rob Miracle to save my game data as gameInfo.json. 

The same JSON will work. The loadsave functionality hides your need to have access to the JSON file. You give it a table, you get a table. But I suppose you could either 

  1. read the saved file back in like load does and instead of converting it to a Lua table, just save the read data in it’s JSON form. JSON is just a big string that represents your table.

  2. Just use json.encode( yourTable ) as the value to GPGS.

  3. Modify your loadsave functions to also write the JSON string to GPGS at the same time it saves it to a local file.

Rob