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 sfg98 · Mar 01, 2014 at 11:07 PM · saveload

Why wount my saving script save properly ?

Hi, im having a problem with my savig script.

the problem is that it will save the first two levels properly, but when i finish the third level it wount write to the file.

Why is it doing that ?

i also tried to add another level to my array of names but it looks like unity wount add it to the array.

ps. it saves the name of the level found in the array to a text file and then another script loads that level when a button is pressed.

The code:

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 using System.IO;
 using System.Text;
 
 public class saver : MonoBehaviour {
 
 
     private string winDir;
     //private List<string> read = new List<string>();
     public string finishedLevel = "aa";
     public string[] levels = {"level3", "2D Learning", "level2", "startMenu"};
 
     private string[] entries;
 
     //public GameObject loader;
     //private levelLoader levelloader;
 
     public int x = 0;
 
     public bool nextLevel = false;
 
     // Use this for initialization
     void Start () {
         winDir= Application.dataPath + "/save.txt";
         //Read ();
 
         //levelloader = loader.GetComponent<levelLoader> ();
         //levels = levelloader.levels;
 
     }
     
     // Update is called once per frame
     void Update () {
         Read ();
         Debug.Log ("update etter READ");
         //Debug.Log ("winDir: " + winDir);
         //Debug.Log ("FILE: " + read);
         Debug.Log ("Entries[0aaa]: " + entries[0]);
         //Debug.Log ("XAAA: " + x);
 
         while(entries[0] != levels[x]) {
             x += 1;
             Debug.Log ("XaAA: " + x);
         }
 
 
         if (nextLevel == true) {
             //x +=1;
             //times +=1;
             Write (levels[x +1]);
             Read ();
             nextLevel = false;
             Debug.Log("Nextlevel");
             //x = 0;
         }
 
     }
 
     void Read(){
             
             string line;
             // Create a new StreamReader, tell it which file to read and what encoding the file
             // was saved as
             StreamReader theReader = new StreamReader(winDir, Encoding.Default);
             
             // Immediately clean up the reader after this block of code is done.
             // You generally use the "using" statement for potentially memory-intensive objects
             // instead of relying on garbage collection.
             // (Do not confuse this with the using directive for namespace at the 
             // beginning of a class!)
             using (theReader)
             {
                 // While there's lines left in the text file, do this:
                 do
                 {
                     line = theReader.ReadLine();
                     
                     if (line != null)
                     {
                         // Do whatever you need to do with the text line, it's a string now
                         // In this example, I split it into arguments based on comma
                         // deliniators, then send that array to DoStuff()
                         entries = line.Split(',');
                         //if (entries.Length > 0)
                         //    doneRead(entries);
                     }
                 }
                 while (line != null);
                 
                 // Done reading, close the reader and return true to broadcast success    
                 theReader.Close();
                 //return true;
             }
         }
     //}
 
     void Write(string levelDONE){
         System.IO.File.WriteAllText(winDir, levelDONE);
 
     }
     /*
     void doneRead(string[] entiress){
 
         //Debug.Log (entiress[0]);
     }
     */
 }
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

0 Replies

· Add your reply
  • Sort: 

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

20 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

Related Questions

Remembering the state of a scene 1 Answer

Load XML File ? 1 Answer

player prefs, problem but no problem??? 1 Answer

Perform action on save/load in editor 2 Answers

Save variable value. 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