Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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.

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

Anyway to save which seen the player was on, then load that scene back from another one at a different time? 2 Answers

How can i make my scene less laggy? 2 Answers

How to start a function from another scene. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges