Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 twoface262 · Dec 18, 2012 at 04:19 PM · androidjavascriptfile-io

Loading from multiple files?

Hello! I'm making a game, and I've already done a simple file-io loading system with text files. How would I make loading slots? Like if the player selects slot 2 it'll only choose the loading files "Slot 2" on them.

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 Catlard · Dec 18, 2012 at 04:41 PM

Well, you're loading the file from a path, right? Just save the save data in different files based on the number of save slots you have. Don't try to put them all in the same one! So your save data .txt file (or whatever kind of data file it is) would be called save2.txt. You can even construct the path based on the int number of the save file. Just take the path string and + saveSlotNumber.ToString() + .txt. Bammo! Done.

Sorry for the long delay! So, I think what you need is to generate the path for the saving text file. I've updated my answer with a script that I have writes text save files. Basically, you need to use a C# StreamReader/StreamWriter or TextReader or TextWriter. Steamreaders and writers can append, but are slightly more costly than TextReaders/Writers. Basically, the other thing you can do is, once you've declared you're "using" the correct namespace (see my script), you can search for the text file of the right number (Check if File.Exists(Save1Path), and so on). It would probably be easiest to limit the number of save slots, so you can just overwrite the states when you need to make a new one or save new data. Hope this helps!

 using UnityEngine;
 using System.Collections;
 using System;
 using System.IO;
 using System.Collections.Generic;
 
 public class AnnotationWriter : SingletonMonoBehaviour<AnnotationWriter>{
     
     private StreamWriter _sW;
     
     public void RecordAnnotationData(List<Annotation> anns) {
         StartRecordingAnnotations();
         if(anns.Count > 0) {
             foreach(Annotation ann in anns)
                 RecordAnnotation(ann);
         }
         _sW.Flush();
         _sW.Close();
     }
     
     public void DeleteAllAnnotationData() {
         File.Delete(BuildManager.instance.GetFilePath(BuildManager.FileType.AnnotationData));    
     }
     
     private void StartRecordingAnnotations() {
         string annotationDataPath = BuildManager.instance.GetFilePath(BuildManager.FileType.AnnotationData);
         
         if(File.Exists(annotationDataPath)) {
             print ("Found the data file at " + annotationDataPath + ". Adding new data.");    
             _sW = new StreamWriter(annotationDataPath, true);
             
         } else {
             _sW = new StreamWriter(annotationDataPath);
             print ("Creating a new data file, because a previous one was not detected.");
 
         }
     }
     
     public void RecordAnnotation(Annotation ann) {
         _sW.WriteLine();    
         _sW.WriteLine(ann._name);
         _sW.WriteLine(ann._explorableTextName);
         _sW.WriteLine(ann._tabName);
         _sW.WriteLine(ann._type);
         _sW.WriteLine(ann._startUVCoords);
         _sW.WriteLine(ann._endUVCoords);
         _sW.WriteLine(ann._entranceTime);
         _sW.WriteLine(ann._timeToAppear);
         _sW.WriteLine(ann._movementStyle);
         _sW.WriteLine(ann._color);
         _sW.WriteLine(ann._fullScale);
         _sW.WriteLine(ann._localPosition);
         _sW.WriteLine(ann._explorableTextLink);
         _sW.WriteLine(ann._tabLink);            
         
         
     }
     
     public void ClearData() {
         
     }
 }

Comment
Add comment · Show 1 · 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 twoface262 · Dec 18, 2012 at 05:32 PM 0
Share

Well how would I tell how many already exist? That's what I'm trying to do save1.txt save2.txt save3.txt and so on, but since it's going to create the slots as it goes ins$$anonymous$$d of having a set number how would I be able to get how many slots there already are, and number them properly?

avatar image
0

Answer by Next Beat Games · Dec 18, 2012 at 05:10 PM

Not quite sure what you are trying to do. Do you mean you would like multiple profiles to save and load game data? Why not use PlayerPrefs?

Stay Tuned for the release of "Scratch Island" on mobile platforms

Comment
Add comment · Show 1 · 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 twoface262 · Dec 19, 2012 at 06:08 PM 0
Share

I'm asking is if I have a folder with multiple save files EX: save1.txt save2.txt save3.txt. How would I make it so it looks through and selects the one that the player selects? and save them according to how many are currently in there and dont have the same name

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

11 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

Related Questions

Load function not working propperly? 1 Answer

Saving items to a text file 1 Answer

Spawning random terrain pieces 1 Answer

Android File-io? 1 Answer

Android Multitouch 0 Answers


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