Broke My Game Trying to Load Array
Posted: Wed Jan 27, 2021 5:37 pm
I've been stuck on this issue for almost a month and today I finally narrowed it down to the fact that I'm just using array saving/ loading wrong.
Basically, I have two arrays, one string and one int. They are storing values and I want to be able to save and load the same values from level to level - this is for an inventory system.
When I'm not using Easy Save they work fine!
As soon as I try and load, I get nothing back and get all sorts of errors.
Here is how I'm calling it:
The "else" is to reset the contents of the arrays back to 0. Not really relevant to this post.
If it helps (don't think it does), here's how I'm saving.
I'm new to Easy Save so I suspect I'm doing this all wrong, but would really appreciate some guidance. Thank you!
Basically, I have two arrays, one string and one int. They are storing values and I want to be able to save and load the same values from level to level - this is for an inventory system.
When I'm not using Easy Save they work fine!
As soon as I try and load, I get nothing back and get all sorts of errors.
Here is how I'm calling it:
Code: Select all
if (ES3.KeyExists("Items Held"))
{
CharacterTracker.instance.itemsHeld = ES3.Load<string[]>("Items Held");
}
else
{
CharacterTracker.instance.itemsHeld = new string[0];
CharacterTracker.instance.itemsHeld = new string[30];
}
if (ES3.KeyExists("Number Of Items"))
{
CharacterTracker.instance.numberOfItems = ES3.Load<int[]>("Number Of Items");
}
else
{
CharacterTracker.instance.numberOfItems = new int[0];
CharacterTracker.instance.numberOfItems = new int[30];
}
If it helps (don't think it does), here's how I'm saving.
Code: Select all
ES3.Save<int[]>("Number Of Items", CharacterTracker.instance.numberOfItems);
ES3.Save<string[]>("Items Held", CharacterTracker.instance.itemsHeld);