- Home /
How do I create multiple save files and make it work?
So I have a player high score system, but I made a new scene which is a top down version of the fps, and I want it to have a different high score then the other. I basically just duplicated the high score system I had from the other scene, changing names etc, but it seems as if it doesnt work even though it is the same as the one ive been using, how do I make it so 2 save files can be made? I cannot use playerprefs.
Here is my script to save the score:
   import System.IO;
    import System.Runtime.Serialization.Formatters.Binary;    //I know, it's a bit long eh? 
  
 var fileName1 = "2dhs.data";
 var ScoreAmount1 : int;
    
 var HighScore1 : int;
    
 function Start (){
     HighScore1 = ScoreLoad1.CompareScore1;
     ScoreAmount1 = GlobalScore.CurrentScore;
     if (ScoreAmount1 >= HighScore1){
         var bf = new BinaryFormatter ();
         var OurFile = File.Open (fileName1, FileMode.OpenOrCreate);
         bf.Serialize (OurFile, ScoreAmount1);
         OurFile.Close();
     }
 }
and my script to load it:
   import System.IO;
   
 var fileName1 = "2dhs.data";
 var ScoreLoad1 : int;
 var HighScoreDisplay1 : GameObject;
   
 static var CompareScore1 : int;
   
 function Start ()
 {
     var bf = new BinaryFormatter ();
     var OurFile = File.Open (fileName1, FileMode.Open);
     ScoreLoad1 = bf.Deserialize (OurFile);
     OurFile.Close ();
   
     HighScoreDisplay1.GetComponent.<Text>().text = ScoreLoad1.ToString();
   
     CompareScore1 = ScoreLoad1;
 }
This is all in javascript. and the scripts I am using for the other (working) high score system are just those scripts except take out all the "1"s and change 2dhs to hs. Thank you
Answer by Cherno · Jun 29, 2017 at 01:17 AM
Change the filename in this line in one of your scripts:
 var fileName1 = "2dhs.data";
for example, in the second line, you change it to
 var fileName1 = "2dhs2.data";
Answer by jemonsuarez · Aug 10, 2017 at 07:49 AM
Serialising an integer is way overkill, I think you should use some easier and faster code for small save-games like yours. Please take a look at FileManagement in the AssetStore, I'm sure you will like it. Best regards.
Your answer
 
 
             Follow this Question
Related Questions
How to load saved data from another scene? 2 Answers
How to save a scene while playing? 1 Answer
How can i make my scene less laggy? 2 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                