Google Cloud Save Issue (solved)

Discussion and help for Easy Save 3
Post Reply
Johnny Star
Posts: 25
Joined: Sat Mar 21, 2020 2:17 pm

Google Cloud Save Issue (solved)

Post by Johnny Star »

Code: Select all

FormatException: Expected '{' or "null", found '1'.
ES3Internal.ES3JSONReader.ReadNullOrCharIgnoreWhitespace (System.Char expectedChar) (at <e070eb114eab438993237e81806ca4dd>:0)
ES3Internal.ES3JSONReader.StartReadObject () (at <e070eb114eab438993237e81806ca4dd>:0)
ES3Reader.ReadObject[T] (System.Object obj, ES3Types.ES3Type type) (at <e070eb114eab438993237e81806ca4dd>:0)
ES3Reader.ReadInto[T] (System.Object obj, ES3Types.ES3Type type) (at <e070eb114eab438993237e81806ca4dd>:0)
ES3.DeserializeInto[T] (ES3Types.ES3Type type, System.Byte[] bytes, T obj, ES3Settings settings) (at <e070eb114eab438993237e81806ca4dd>:0)
ES3File.LoadInto[T] (System.String key, T obj) (at <e070eb114eab438993237e81806ca4dd>:0)
ES3.LoadInto[T] (System.String key, T obj, ES3Settings settings) (at <e070eb114eab438993237e81806ca4dd>:0)
ES3.LoadInto (System.String key, System.Object obj, ES3Settings settings) (at <e070eb114eab438993237e81806ca4dd>:0)
Wallet.ReplaceWithCloudSavedData (System.Byte[] data) (at <e070eb114eab438993237e81806ca4dd>:0)
CloudGameSave+<>c.<ReadSavedGame>b__8_0 (EasyMobile.SavedGame game, System.Byte[] data, System.String error) (at <e070eb114eab438993237e81806ca4dd>:0)
EasyMobile.Internal.GameServices.AndroidSavedGameClient+<>c_DisplayClass3_0.<ReadSavedGameData>b_0 (GooglePlayGames.BasicApi.SavedGame.SavedGameRequestStatus status, System.Byte[] data) (at <e070eb114eab438993237e81806ca4dd>:0)
GooglePlayGames.Android.AndroidSavedGameClient+<>c_DisplayClass15_1`2[T1,T2].<ToOnGameThread>b_1 () (at <e070eb114eab438993237e81806ca4dd>:0)
GooglePlayGames.OurUtils.PlayGamesHelperObject.Update () (at <e070eb114eab438993237e81806ca4dd>:0)
I'm receieving the error above.

This is my saving code:

Code: Select all

    private void SaveWalletCloud()
    {
        if (EasyMobile.RuntimeManager.IsInitialized() == false || EasyMobile.GameServices.IsInitialized() == false || EasyMobile.EM_Settings.GameServices.IsSavedGamesEnabled == false)
        {
            HelperMethods.LogErr($"<b>Wallet ►</b> Requested cloud saving but conditions not met.");
            return;
        }

        var cacheSettings = new ES3Settings(ES3.Location.Cache);
        ES3.Save<int>("collectableGoldCoin", collectableGoldCoin, cacheSettings);
        ES3.Save<int>("collectableDiamond", collectableDiamond, cacheSettings);
        byte[] bytes = ES3.LoadRawBytes(cacheSettings);

        HelperMethods.Log(HelperMethods.LogHandle().Wallet, $"<b>Wallet ►</b> Attempting to save to cloud. Bytes to save: {Convert.ToBase64String(bytes)}");

        GameData.GetInstance().StartCoroutine(GameData.GetInstance().CloudGameSave.PushDataToCloud(bytes));
    }
The supplied bytes data in the debug log is this:

Code: Select all

<b>Wallet ►</b> Attempting to save to cloud. Bytes to save: ewoJImNvbGxlY3RhYmxlR29sZENvaW4iIDogewoJCSJfX3R5cGUiIDogIlN5c3RlbS5JbnQzMiIsCgkJInZhbHVlIiA6IDEwNTgKCX0sCgkiY29sbGVjdGFibGVEaWFtb25kIiA6IHsKCQkiX190eXBlIiA6ICJTeXN0ZW0uSW50MzIiLAoJCSJ2YWx1ZSIgOiAxMDAKCX0KfQ==
This is my retrieving > overwriting code:

Code: Select all

    public void ReplaceWithCloudSavedData(byte[] data)
    {
        HelperMethods.Log(HelperMethods.LogHandle().Wallet, $"<b>Wallet ►</b> Overwriting local data with the data retrieved from cloud. Bytes retrieved: {Convert.ToBase64String(data)}");

        var cacheSettings = new ES3Settings(ES3.Location.Cache);
        ES3.SaveRaw(data, cacheSettings);
        ES3.LoadInto("collectableGoldCoin", collectableGoldCoin, cacheSettings);
        ES3.LoadInto("collectableDiamond", collectableDiamond, cacheSettings);
    }
The supplied bytes data in the debug log is this:

Code: Select all

<b>Wallet ►</b> Overwriting local data with the data retrieved from cloud. Bytes retrieved: ewoJImNvbGxlY3RhYmxlR29sZENvaW4iIDogewoJCSJfX3R5cGUiIDogIlN5c3RlbS5JbnQzMiIsCgkJInZhbHVlIiA6IDEwNTgKCX0sCgkiY29sbGVjdGFibGVEaWFtb25kIiA6IHsKCQkiX190eXBlIiA6ICJTeXN0ZW0uSW50MzIiLAoJCSJ2YWx1ZSIgOiAxMDAKCX0KfQ==
Both bytes is the same. Why does the error occur?
Last edited by Johnny Star on Thu Aug 27, 2020 7:41 am, edited 1 time in total.

Johnny Star
Posts: 25
Joined: Sat Mar 21, 2020 2:17 pm

Re: Google Cloud Save Issue

Post by Johnny Star »

Fixed it. LoadInto function is broken. Just use load and it will work fine.

User avatar
Joel
Moodkie Staff
Posts: 2973
Joined: Wed Nov 07, 2012 10:32 pm

Re: Google Cloud Save Issue (solved)

Post by Joel »

Hi there,

Would you be able to provide more information on how the LoadInto function is broken? We've had no reports of this and I don't appear to be able to replicate this at my end.

All the best,
Joel
Joel @ Moodkie Interactive
Twitter - Unity

Johnny Star
Posts: 25
Joined: Sat Mar 21, 2020 2:17 pm

Re: Google Cloud Save Issue (solved)

Post by Johnny Star »

Actually, I don't know. I just changed my code to this and the error shown above went away.

Code: Select all

        var cacheSettings = new ES3Settings(ES3.Location.Cache);
        ES3.SaveRaw(data, cacheSettings);

        // Overwrite gold coin.
        collectableGoldCoin = ES3.Load<int>("collectableGoldCoin", cacheSettings);
        ES3.Save<int>("collectableGoldCoin", collectableGoldCoin);

        // Overwrite diamond.
        collectableDiamond = ES3.Load<int>("collectableDiamond", cacheSettings);
        ES3.Save<int>("collectableDiamond", collectableDiamond);

User avatar
Joel
Moodkie Staff
Posts: 2973
Joined: Wed Nov 07, 2012 10:32 pm

Re: Google Cloud Save Issue (solved)

Post by Joel »

Hi there,

ES3.LoadInto is used to load data into an existing reference, but the data you're loading isn't a reference type, causing the issue you're encountering.

All the best,
Joel
Joel @ Moodkie Interactive
Twitter - Unity

Post Reply