Gpgs - cloud save and snapshots

Hi @Defold team and Community :slight_smile:

I am currently playing around with the gpgs extension, since i wanted to use it in my current project. In had in mind to use it for storing highscores and other user data (save games). While the highscore part was rather easy, i am struggling a bit with saving user related data.

Here are the relevant parts of my code for saving any data:
onMessage function:

if message_id == hash("addCoins") then
	print("addCoins message received")
	gpgs.snapshot_open("coins", true, gpgs.RESOLUTION_POLICY_LAST_KNOWN_GOOD)
	local success, error_message = gpgs.snapshot_set_data(10)
	if error_message then
		print(error_message)
	end
		
	gpgs.snapshot_commit_and_close()
	local bytes, error_message = gpgs.snapshot_get_data()
end

update function:
print("snapshot open: " .. tostring(gpgs.snapshot_is_opened()))

generated log of my application:
04-25 18:43:21.891 6336 6369 D defold : DEBUG:SCRIPT: snapshot open: false
04-25 18:43:21.908 6336 6369 D defold : DEBUG:SCRIPT: snapshot open: false
04-25 18:43:21.925 6336 6369 D defold : DEBUG:SCRIPT: snapshot open: false
04-25 18:43:21.943 6336 6369 D defold : DEBUG:SCRIPT: snapshot open: false
04-25 18:43:21.959 6336 6369 D defold : DEBUG:SCRIPT: snapshot open: false
04-25 18:43:21.975 6336 6369 D defold : DEBUG:SCRIPT: button pressed
04-25 18:43:21.976 6336 6369 D defold : DEBUG:SCRIPT: addCoins message received
04-25 18:43:21.979 6336 6369 D defold : DEBUG:SCRIPT: Can’t write data to the snapshot. The snapshot wasn’t open.
04-25 18:43:21.979 6336 6369 D defold : DEBUG:SCRIPT: snapshot open: false
04-25 18:43:21.993 6336 6369 D defold : DEBUG:SCRIPT: snapshot open: false
04-25 18:43:22.009 6336 6369 D defold : DEBUG:SCRIPT: snapshot open: false
04-25 18:43:22.027 6336 6369 D defold : DEBUG:SCRIPT: snapshot open: false

Use save games is enabled in google play console and in the game.project file. Still the snapshot is never opened. Is my code wrong? Do you have any idea what else i could check? Any input is appreciated :slight_smile:

Have you compared your usage with the example that is packaged with the extension? Have you checked the readme?

yes, i checked the code example. i just realized that there is a message when the snapshot was opened, so i checked what happens when i receive this message. this is a part of the code of my gpgs callback:

elseif message_id == gpgs.MSG_LOAD_SNAPSHOT then
	print("------gpgs load snapshot------")
	print(dump(message))
	print("is logged in: " .. tostring(gpgs.is_logged_in()))
end

which produces this output:
04-25 20:18:30.628 16390 16420 D defold : DEBUG:SCRIPT: ------gpgs load snapshot------
04-25 20:18:30.629 16390 16420 D defold : DEBUG:SCRIPT: { [“error”] = Error while opening Snapshot: SIGN_IN_REQUIRED (4),[“error_status”] = 4,[“status”] = 2,}
04-25 20:18:30.629 16390 16420 D defold : DEBUG:SCRIPT: is logged in: true

not sure whats going on there. receiving an error message SIGN_IN_REQUIRED while i am clearly logged in…

Please, make sure that in game.project in section gpgs option use_saved_games is 1

it is set, also in the developer console use save games is active.

i just tried out the code example from https://defold.com/extension-gpgs/ (with very small adjustments)
unfortunately it does the same thing :frowning:

		gpgs.snapshot_display_saves("My saves", true, true, 3)
		gpgs.snapshot_open("my_save", true, gpgs.RESOLUTION_POLICY_MANUAL)

		local success, error_message = gpgs.snapshot_set_data("MyCustomBytesForSnapshot")

		local bytes, error_message = gpgs.snapshot_get_data()
		local bytes, error_message = gpgs.snapshot_get_conflicting_data()

		gpgs.snapshot_commit_and_close({
			description = "LEVEL 31, CAVE",
			playedTime = 1000,
			progressValue = 1234
		})

		gpgs.snapshot_is_opened()

When did you do that?

In the official instruction they have this note:

After performing the steps above, it may take up to 24 hours for Google Play games services to activate the Saved Games feature for your game. If you want to test the Saved Games feature immediately, manually clear the data in the Google Play Services app installed on your test device.

2 Likes

its working now, my phone was connected to the wrong account all along :see_no_evil: thanks for all the help!

still i am having a small issue with snapshots. often i am getting an error message: “Failed to load snapshot.” when calling gpgs.snapshot_get_data()
any idea, the error message does not give a lot of hints