Loading / saving ALL my data

Ok, editing this to make it much more concise. Here are the basics:

I’m using a save / load script which works, except I need to plug in more variables. In other words, the script is designed from the go to save player position, but nothing else. So I’m trying to call stats from a couple of different scripts for saving (such as current health, experience, etc.) with no success. Below is a small chunk of the script, the area I’ve identified as being pertinent to this question. (I realize that with my lack of experience I may be completely wrong)

//LoadingPlayers ************************************************************      
    if (GUI.Button(_Load,"Load")) {
      
      GUI.Label(_LoadMSG,"Loading from: "+_FileLocation);
      // Load our UserData into myData
      LoadXML();
      if(_data.ToString() != "")
      {
         myData = DeserializeObject(_data);
         VPosition=new Vector3(myData._iUser.x,myData._iUser.y,myData._iUser.z);             
         player.transform.position=VPosition;
         curExperience = Playerhealth.curXp;
         Debug.Log("Load Successful");
      }
   		 
   }
   //EndOfLoadingPlayers *******************************************************
   
   //SavingPlayers *************************************************************
   if (GUI.Button(_Save,"Save")) {
            
      GUI.Label(_SaveMSG,"Saving to: "+_FileLocation);
      //Debug.Log("SaveLoadXML: sanity check:"+ player.transform.position.x);
      
      myData._iUser.x = player.transform.position.x;
      myData._iUser.y = player.transform.position.y;
      myData._iUser.z = player.transform.position.z;
      myData._iUser.name = playerName;
      myData._iUser.curExperience = Playerhealth.curXp; 
      myData._iUser.curExperience = Playerhealth.curHealth;

Look directly above. The last two lines are what I modified to try and pull from those two scripts, whereas everything preceding those are original, before I modified anything. AND… nothing changes. Player position loads fine, but nothing I tried to save. There is much more to the script, and maybe a variable needs to be saved somewhere, I don’t know. I can place the entire script in a couple of comments below, if necessary. Thanks to anyone who is able to help me with this problem, which has me pulling my hair out. God bless.

If I could help you with PlayerPrefs then:

var playerLevel : int = 14;
var playerMoney : float = 2391.50;
var killedBosses : int = 24;
var otherVariableEtc : String = "other Variable Can Be String";

var playerDataString = "" + playerLevel + "," + playerMoney + "," + killedBosses + "," + otherVariableEtc + "";
PlayerPrefs.SetString("PlayerData", playerDataString);

The variable playerDataString which you can use print (playerDataString); on the next line to double check, would look something like this: 14,2391.50,24,other Variable Can Be String

The entire string is saved as one playerPref – but can include floats, strings, ints or booleans. The 2nd line saves the playerPref as a string (SetString), called “PlayerData”, with playerDataString as the content.

Getting the data back isn’t much more complicated:

var playerDataCombined = PlayerPrefs.GetString("PlayerData");     // GetString saved in PlayerPrefs called "PlayerData"
var playerData = playerDataCombined.Split(","[0]);      // .Split will create an array (called playerData).  Each comma is removed, and what's between is a unique entry into the array.

playerLevel = parseInt(playerData[0]);
playerMoney = parseFloat(playerData[1]);
killedBosses = parseInt(playerData[2]);
otherVariableEtc = playerData[3]);

That last four lines puts the data from your PlayerData array into your original variables – so you’d do that on Start(). The data in the array are all strings, so for floats and ints, you need to use the parseInt or parseFloat to change the type from a string to a float or int.

Hopefully that makes sense!

EDIT: For your items, do the same thing, but make a unique playerPref for items, perhaps called “PlayerItems”. When saving, do a for loop to include all of the item names or IDs in the string you will be saving (the one with commas).

On start, do this same retrieval method but make it specific to your items, since your items may be stored differently.

— The same thing can be done with enemies and item pickups, including instantiating enemies at the proper spots with the proper HPs and such, if you think about it a bit more —