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
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
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…
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.
its working now, my phone was connected to the wrong account all along 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