Page 1 of 1

Array with Bools

Posted: Wed Oct 13, 2021 6:42 pm
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

Re: Array with Bools

Posted: Thu Oct 14, 2021 9:48 am
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