Iakobs / godot-play-game-services

A Godot 4.x plugin for integration with Google Play Game Services
MIT License
120 stars 7 forks source link

Question: Save Data only with String? #7

Closed Draethos closed 8 months ago

Draethos commented 8 months ago

So the question is the same as the title, is it only possible to save data on google with the use of strings, or can I change it to a dictionary and it would work the same? because idk how to make a string that holds more than 20 variables and get them back again. Thank you.

Iakobs commented 8 months ago

hi @Draethos

when loading a game, the game_loaded signal is emitted. If you subscribe to that signal, you will receive a dictionary with a key named content, which contains the same array of bytes that you sent when saving it.

While this is the most flexible approach, it also comes with a handicap: you have to code your own parser from whatever object or data structure that you want to save to an array of bytes, and vice-versa.

In the demo project I use a simple string, but you will notice that I use the parser methods from Godot's String class. I'm not sure now, but I think Godot has parse methods for most types, so if you want to use a dictionary, maybe there's a method to do so.

If not, I will recommend converting the Dictionary to a JSON String, and the String to an array of byes when saving the game, and the other way around when you load the game.

I hope it makes sense!

Draethos commented 8 months ago

Im really sorry but im self taught so most of it sounded like gibberish to me. Im gonna check the demo project again but i really dont understand java yet so im having trouble making out anything. Wish me luck

Iakobs commented 8 months ago

oh sorry! I see, no worries. You have to do the parsing in godot though, so you don't need any java.

What do you want to save, meaning, a dictionary? an object of your own? I can come with an example to make it easier for you, but I need to know an example of what you want to save 😊

Draethos commented 8 months ago

omg tysm, euhmm i wanna save like a lot of variables, and i dont know how. They are both booleans and integers so i thought holding them in a dictionary would be simple to do and then get them back. If you know a better way (considering its ure plugin) i need to save like 15 of them.Thank you so much

Iakobs commented 8 months ago

I'm checking how to do this, and seems more steps than expected. I can't work out an example for you right now, I'm sorry, but you have this excellent guide in Godot documentation about saving game data to the local storage.

The process they describe is, summarised:

When writing: Save the data as a dictionary > convert the dictionary to a json string > save the string to a local file When reading: read the local file you wrote as a json string > convert the json string back to a Dictionary > You can now access the data from the Dictionary again!

If you manage to store locally the data that you want as a JSON string in a file, you can also send that same JSON string to the plugin as I do in the demo, because at the end is always a String, and for loading/reading it will be also the same.

I hope this helps! Input/Ouput is one of the most boring topics in programming (at least for me!), so don't give up and you will feel like a hacker once you eventually do it!!!

Draethos commented 8 months ago

I understand what you mean and i have done it before, but i want to save it ON google, and i cant save it to a local file, i need to save it on THEIR servers no?Or is the string u mentioned possible to give JSON string to it

Iakobs commented 8 months ago

yes, you have to save it on their servers and if you have the JSON string of the dictionary, you can just send to Google that string parsed as an array of bytes, as I do in the demo project using the to_utf8_buffer() method, and then parsing the array of bytes back to a string with the get_string_from_utf8() method.

So the process is:

writing: save data in Dictionary > Convert dictionary to JSON string > parse JSON string to array of bytes > send to Google

And the other way around when loading. Hope it makes sense!

Draethos commented 8 months ago

Ill try it tommorow, ty for the help mate and hope u have a great week again.

Iakobs commented 8 months ago

I'm curious to know if you managed to solve it :)

Draethos commented 8 months ago

So im trying to see if im able to save at ALL. the show saved games is working perfectly but saving games and loading them is not working atm. im checking different things to see if anything is fking it over but idk yet

Draethos commented 8 months ago

So quick question, do i need it in open testing or released or something for the saving to work? because i cant seem to save anything. I even just saved a packedbytearray to try it out and it doesnt seem to save succesfully. Idk if there is conflict cause the conflict emmitter doesnt seem to print anything and idk what im supposed to do. Ty

Draethos commented 8 months ago

So quick question, do i need it in open testing or released or something for the saving to work? because i cant seem to save anything. I even just saved a packedbytearray to try it out and it doesnt seem to save succesfully. Idk if there is conflict cause the conflict emmitter doesnt seem to print anything and idk what im supposed to do. Ty

Iakobs commented 8 months ago

Hi!

You don't need to haven an open track for your app to test Play Games Services, you only have to properly configure the Play Games Services and publish them there, not in the app tracks. The Google Play Console in general is VERY confusing, at least it was to me.

First of all, you have to turn on save games in the Games Services configuration of your play console:

imagen

If you make any modification, remember to publish it afterwards. This should be enough to save games. You should be able to use the demo project with your app id and load and save games if everything is correctly configured in the Play Console.

Draethos commented 8 months ago

ok then idk. Ill upload the demo project tonight then and check if it instantly works with ure setup. Otherwise something wrong must be happening

Draethos commented 8 months ago

Hey @Iakobs, can u tell me all the permissions I need in all locations such as godot, google and other locations? cause even ure demo doesnt allow me to save. I can SEE my saved games(its empty) and even all achievements and leaderboards. Even players, but saving doesnt. IF possible, please tell me cause im going crazy, its been a month and saving hasnt worked on all plugins ive tried. Thank you very much and have a great week.

Iakobs commented 8 months ago

I'm so sorry to hear that. I can't think of any special permissions needed or something, a part from what we just talk. Can you record a video of my demo app running with your app id, package name etc, saving some data and then loading it? also, I think you said you don't know how to use logcat, right? that would be helpful too. Would you give it a try? this guide shows you how to do it.

Draethos commented 8 months ago

I do know how to use logcat, but i instantly used ure demo and idk if there are any prints in it so idk how to check if something happened other than looking u know? Ill try to send a video later tomorrow cause i cant anymore today but it just looks normal really, nothing crashes or anything but it NEVER saves

Iakobs commented 8 months ago

No worries, pal. Take some rest and let's see if we can make it work for you :)

In order to filter the logs from logcat, you can use a package:package.of.your.game filter, here you have a video of my demo app saving and loading some game data, and the output in the logs.

You can also add the package:com.google.android.gms filter to logcat to see logs from Google, but they are really verbose and most times they just clutter everything.

https://github.com/Iakobs/godot-play-game-services/assets/10604600/4339ba07-66b3-4508-88d2-bbaf25046f34

Draethos commented 8 months ago

Hey man sorry it took so long, so for the past week ive been TRYING to get it to work, ive been doing prints on everything and nothing is working when it comes to saving. EVERYTHING else works so im think of trying to save THROUGH achievements and leaderboards cause i got no other idea anymore. I hope it works this way and if not, WELP.

Iakobs commented 8 months ago

Oh man I'm so sorry to hear that 😢

Only thing I can think of now is if you want to give me access to your code somehow, if you feel comofortable doing so, so I can try to debug it and see if I can find anything.

Draethos commented 8 months ago

Its not even my code though only, ure demo isnt working either. I think the whole thing has something missing or google itself isnt allowing me to save. So its fine man and ty for the trouble ill see if i need anything anymore and open another issue if need be.

Iakobs commented 8 months ago

Oh yes, it's true that you tried with my demo. If everything else is working but the save games, it looks like the game id you are using doesn't have save games configured, did you check the configuration I showed you the other day? this one:

imagen

Also, I'm closing the issue as it appears not to be a problem with the plugin :)

Draethos commented 8 months ago

I did check it mate thank you for pointing it out, i think it has something with my country cause EVERYTHING is turned on at this point and its not working.

Iakobs commented 8 months ago

I'm so sorry to hear that. Hope you enjoy the rest of the features of the plugin!