Saving / Loading Arrays

Discussion and help for Easy Save 3
Post Reply
George
Posts: 3
Joined: Fri Nov 20, 2020 6:15 pm

Saving / Loading Arrays

Post by George »

Hi - I'm trying to save / load an array but keep hitting errors. Can anyone please help describe what I'm doing wrong here and how to fix it up? Many thanks in advance!

Code: Select all

int[] ii = new int[2];
ii[0] = 99;
ii[1] = 100;
ES3.Save("key", ii);

int[] kk = ES3.Load<int[]>("key");
Debug.Log(kk[0]);  // Expected this to print 99, but fails as kk is null.
Debug.Log(kk[1]);
Have also tried using LoadInto (with a pre-allocated kk of the right size) but that returns an error "Object reference not set to an instance of an object", so presume that I've just misunderstood how to use arrays completely here!
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving / Loading Arrays

Post by Joel »

Hi George,

I just tried your code and it appears to be working fine at my end? For reference I tested it with this script:

Code: Select all

using UnityEngine;

public class Test : MonoBehaviour
{
    void Start()
    {
        int[] ii = new int[2];
        ii[0] = 99;
        ii[1] = 100;
        ES3.Save("key", ii);

        int[] kk = ES3.Load<int[]>("key");
        Debug.Log(kk[0]);  // Expected this to print 99, but fails as kk is null.
        Debug.Log(kk[1]);
    }
}
See the attached image for the output. Please could you create a new project with the above script and private message it to me if it's still not working for you?

All the best,
Joel
Attachments
Capture.PNG
Capture.PNG (19.83 KiB) Viewed 1312 times
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
George
Posts: 3
Joined: Fri Nov 20, 2020 6:15 pm

Re: Saving / Loading Arrays

Post by George »

Thank you for the quick reply!

I've managed to create a repro scenario - in the runtime settings window just change the default encoding from JSON to Binary_Alpha. With the former the script works, and with the latter it doesn't. Is this a bug or expected behaviour?
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving / Loading Arrays

Post by Joel »

Hi there,

Binary_alpha is only used internally and shouldn't be used. Just to clarify, unless the setting is documented you shouldn't change it from default.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
George
Posts: 3
Joined: Fri Nov 20, 2020 6:15 pm

Re: Saving / Loading Arrays

Post by George »

OK, understood - thank you again for the quick responses!
Post Reply