Array with Bools

Discussion and help for Easy Save 3
Post Reply
sunnybecks
Posts: 1
Joined: Wed Oct 13, 2021 6:34 pm

Array with Bools

Post by sunnybecks »

Hi, i am new with using ES3.

i want to save and load an array of bools, but it seems not to work.

Code: Select all

 public void SaveAllCoins()
    {
        for (int i = 0; i < Coin.Length; i++)
        {
            ES3.Save("Coin", Coin[i]);
        }
    }
      public void LoadAllCoins()
    {
        for (int i = 0; i < Coin.Length; i++)
        {
            Coin[i] = ES3.Load<bool>("Coin");
        } 
    }
    
    
If i assign a specific Coin in the for loop like

Code: Select all

 
Coin[6]=ES3.Load<bool>("Coin") 
ES3.Save("Coin",Coin[6]) 
then it works. Do somebody have a tip for me what i am doing wrong? And if i look at the SaveFile then there are still no entrys. Do i have to push it with code from cached data? Thank you
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Array with Bools

Post by Joel »

Hi there,

You’re not saving an array of bools in your code, you’re saving each bool separately to the same key, meaning you’re constantly overwriting the data.

In your case you shouldn’t loop over your Coin array and should instead save the Coin array itself.

I.e.
ES3.Save(“Coin”, Coin);

And to load:

Coin = ES3.Load<bool[]>(“Coin”);

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply