Saving a list of items

Hi all, I asked this same question a couple months ago and got a lot of help, but I still could not figure it out so I just went on to work on other things. I’m at a point now where I really need to figure this out so I can finish my project. I have a better understanding now so hopefully I can phrase a better question. So here we go…

I have a list of items (Inventory) and each item in the list inherits from a custom class called ‘Item’ which contains string, int, and enum values as well as a texture2d. What I am trying to do is save all of the items in the Inventory list by converting the data in the Item class to strings so I can store them in a temporary string array, and then convert everything back to its original data when loading. I’m getting an error at the line I marked that says ‘Format Exception: Input string was not in the correct format.’ I’ll put my current code up so you can see where I’m at.

//GameSettings.js
var tempArray : String[];
var temp : String;
var Inventory; 
var convertVariables : Item;
               
function SaveData() {
Inventory = GameObject.Find("GUIElements").GetComponent("Inventory").inventory;
for(i = 0; i < Inventory.Count; i++) {
                
if(i != Inventory.Count - 1){
convertVariables.ConvertVariables();
temp += Inventory_.ToString() + "*";_

}

else{
convertVariables.ConvertVariables();
temp += Inventory*.ToString();*
}
}
PlayerPrefs.SetString(“InventoryItems”,temp);
}

function LoadData() {

temp = PlayerPrefs.GetString(“InventoryItems”);
tempArray = temp.Split(“*”.ToCharArray());

for(i = 0; i < tempArray.Length; i++){
Inventory = System.Int32.Parse(tempArray*); <<<ERROR OCCURS HERE*
}
}

//Item.js
function ConvertVariables() {
//Ints to convert
price.ToString();
minDamage.ToString();
maxDamage.ToString();
defense.ToString();
healthAmount.ToString();
essenceAmount.ToString();
itemLevel.ToString();
itemFireDamage.ToString();
itemIceDamage.ToString();
itemLightningDamage.ToString();
itemElementDamage.ToString();
curDura.ToString();
maxDura.ToString();

//Enums to convert
rarity.ToString();
jewelSlot.ToString();
consumableType.ToString();
armorType.ToString();
armorSlot.ToString();
weaponSlot.ToString();
weaponSlot2.ToString();
weaponDamageType.ToString();
weaponType.ToString();
itemArchetype.ToString();
itemElementType.ToString();

Debug.Log(“Variables Converted”);
}
The ‘ConvertVariables’ function obviously is used to convert the ints and enums to strings. What I’m wondering is it possible or even necessary to convert the texture2d to a string? I’m curious because I’m not sure if that’s what is causing the error or not. Anyways that’s where I’m at right now, if anyone could give some insight it would be greatly appreciated. If you need any more info or code sample I’ll be happy to provide it. Thank you!

You have “saved” your data to PlayerPrefs? Try to substitute this:

for(i = 0; i < tempArray.Length; i++){
Inventory _= System.Int32.Parse(tempArray*);*_

}
with this:
for(i = 0; i < tempArray.Length; i++){
Debug.Log(tempArray*);*
//Inventory = System.Int32.Parse(tempArray*);*
}
What does it print out?
Maybe it`s about your enums? Try the Enum.Parse method for those.