• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ChompIV · Jun 29, 2017 at 12:48 AM · javascriptscenesavescorefile-io

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

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";
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

114 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to load saved data from another scene? 2 Answers

How to save a scene while playing? 1 Answer

Saving and loading a GameObject built in-game 2 Answers

Problem with restarting the scene (js) 2 Answers

Please Help!!! my LineRenderer Script is not show when bulid on android device 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges