Using Easy Save alongside Easy Mobile Pro (Questions)

Discussion and help for Easy Save 3
Post Reply
Archieonic
Posts: 4
Joined: Fri Dec 13, 2019 8:18 pm

Using Easy Save alongside Easy Mobile Pro (Questions)

Post by Archieonic »

Hello! So I'm fairly new to programming (started 2 weeks ago to be specific). I have a prototype game all setup yet missing the save and cloud system. After some researching and plenty of recommendations I decided to get Easy Save and Easy Mobile Pro. Sadly the documentation for Easy Mobile Pro opening, writing and loading from Google Play Services and iCloud is leaving me in the dust. I was hoping maybe I could get some clarification here on how to use data saved through Easy Save and upload it to those services.

So far as I understand it, Google Play Services loads byte arrays. So I'd have to save values with Easy Save 3 with the method:

Code: Select all

    var es3File = new ES3File(false);
        SphereValues sphereV = sphere.GetComponent<SphereValues>();
        es3File.Save<int>("sphereWeight", sphereV.sphereWeight);
        es3File.Save<float>("sphereRadius", sphereV.sphereRadius);

        byte[] fileAsByteArray = es3File.LoadRawBytes();
Now I have the saved data as a byte array, and need to process it to Google Play. However, I notice that method does not write a file (I believe it writes to memory?). Easy Mobile Pro has a method for writing to a saved game (locally and then uploads it). So in my mind, I should carry this newly created byte array over there to be written and uploaded, but I can't for the life of me figure out how to do that or if that method of getting byte arrays from Easy Save is the correct one. It might be a long shot, but perhaps someone here has experience trying to integrate these 2 plugins together and can help me out? Thanks in advanced!
Archieonic
Posts: 4
Joined: Fri Dec 13, 2019 8:18 pm

Re: Using Easy Save alongside Easy Mobile Pro (Questions)

Post by Archieonic »

I've made a lot of progress, however I've stumbled upon an error that I can't understand.

Code: Select all

        var unlocked = new ES3File(false);
        unlocked.Save<int>("UnlockedLevels", unlockedLevels);
        byte[] unlockedArray = unlocked.LoadRawBytes();
        ES3.AppendRaw(unlockedArray, "savedGame.bytes");
It highlights the last part "savedGame.bytes" saying "Cannot convert from string to ES3Settings" but looking at the documentation that should be valid? It works with ES2.AppendRaw.

I'm trying to append a per level score system in one single file (since i need to upload that to Google Play Services) but append simply keeps on adding, I'm trying to find a way of overwriting just one value.

Edit
Worked using Easy Save 2 functions and a simple if function checking if the current level was higher than the current unlocked levels saved in a file.

My main problem right now is how to get those saved files loaded from Google Play Services. I can feed the info no problem, but when I fetch it (which comes as a byte array), I can't figure out how to load each value where it belongs. Any ideas please?
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Using Easy Save alongside Easy Mobile Pro (Questions)

Post by Joel »

Hi there,

If you want to store the data locally you can use the ES3.Save methods. Then to get the local file as a byte array, use ES3.LoadRawBytes.

To save back to a file you can use ES3.SaveRaw, and then use the ES3.Load methods to load the data.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Archieonic
Posts: 4
Joined: Fri Dec 13, 2019 8:18 pm

Re: Using Easy Save alongside Easy Mobile Pro (Questions)

Post by Archieonic »

Hey there! Thanks for the reply, just tonight I managed to get everything working in sync.

I still don't quite get it but, the byte arrays and the regular ES3.Save seem to do the same thing? Once I take a file saved with ES3.Save and load it as an array (ES3.LoadRawBytes), feed it to the Google Play Saved Game API, then retrieve it and open it locally (by overwriting the current local save file with the cloud one), it works all the same. I'm able to use ES3.Load<int>("key", "filePath") on the byte array and it works all the same. Maybe it is due to my ignorance of how serialization and byte arrays work, but it seems to work. My current setup is as follows:

Code: Select all

        if (endScore >= 0.25f && endScore <= 0.5f)
        {
            Debug.Log("Save 1 star");
            int unlockedLevels = gameManager.currentScene;
            int currentUnlockedLevels = ES3.Load<int>("unlockedLevels", "playerData");
            if (currentUnlockedLevels < gameManager.currentScene)
            {
                ES3.Save<int>("unlockedLevels", unlockedLevels, "playerData");
                ES3.Save<int>("Highscore" + gameManager.currentScene, endScoreInt, "playerData");
            }
        }

//repeat to check score ranges
        byte[] savedGame = ES3.LoadRawBytes("playerData");
        gameManager.WriteSavedGame(gameManager.mySavedGame, savedGame);
        gameManager.ResetScore();
Here, based on player score I increased the unlocked levels by one if conditions are met and save the star amount based on score. Then when the if statements are done, it converts the entire playerData file into a byte array and calls the function to commit the save to the cloud. Now, upon reading a cloud save, I use Easy Save 3 to overwrite the current local file and start using that for all values with:

Code: Select all

                        if (data.Length > 0)
                        {
                            byte[] loadedSave = data;
                            ES3.SaveRaw(loadedSave, "playerData");        //Overwrite current local data to be used.
                        }
Now I can use ES3.Load on that byte array as if it were a regular ES3.Save file. In fact, both the LoadRawBytes and ES3.Save yield the exact same file. Maybe I'm completely oblivious to how it all works internally, but it just seems to work perfectly. I was under the impression that ES3.Load could not read from a byte array, but it can (as you pointed out). Am I incorrect in any of these assumptions? Thanks!

PS: Pardon if it sounds all too noobish, I started programming and learning C# 2 weeks ago so a lot of these concepts fly over my head.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Using Easy Save alongside Easy Mobile Pro (Questions)

Post by Joel »

Hi there,

Easy Save can Load from this byte array because the byte array has been stored locally as a file.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Archieonic
Posts: 4
Joined: Fri Dec 13, 2019 8:18 pm

Re: Using Easy Save alongside Easy Mobile Pro (Questions)

Post by Archieonic »

Ah, my confusion. I somehow thought ES3.Load could load only files saved with ES3.Save, and couldn't do so for ES3.SaveRaw files or any array files for that matter.
Post Reply