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 Creeper_Math · Jan 07, 2017 at 03:04 PM · c#savingfilesramwrite data

Saving File from "RAM" string array only saving one file

I have a custom RAM string array that only loads "files" to it when another script accesses that file. I also have a script that looks for all the files loaded on the RAM and saves it every 5 seconds. Here's the script that is on an InvokeRepeating for every 5 seconds

Format of the RAM Data: File Separator is marked by "RAMFileFormatHeader" (which currently is ========== ) Next is the file that the Data is followed by Third is the time before the file is unloaded from RAM Last is all the data

 void SaveAllRam() {
         // Get all the names in ram
         string[] RAMNames = new string[0];
         int Selection = 0;
         foreach (string item in RAM) {
             if (item == RAMFileFormatHeader) {
                 RAMNames = Command.ArrayAddString(RAMNames, RAM[Selection + 1]);
                 Debug.Log("Found File on RAM '" + RAM[Selection + 1] + "'");
             }
             Selection += 1;
         }
         foreach (string item in RAMNames) {
             
             SaveRAMData(item);
             Debug.Log("Saved File From Ram '" + item + "'");
         }
     }

Here is the File Saving Script that it uses

 // THE "GetData" has been updated as I rewrote it
 static public string[] GetData(string FilePath, bool UpdateData = true, float TimeToLoadFor = 10) {
     LoadDataToRam(FilePath, UpdateData, TimeToLoadFor);
     string[] Data = new string[0];
     int RAMSelector = 0;
     foreach (string item in RAM) {
         if (item == RAMFileFormatHeader && RAM[RAMSelector + 1] == FilePath) {
             for (int WriteSelector = RAMSelector + 4; RAM[WriteSelector] != RAMFileFormatHeader; WriteSelector++) {
                 Data = Command.ArrayAddString(Data, RAM[WriteSelector]);
             }
             return (Data);
         }
     }
     return (new string[0]);
 }


 static public void SaveRAMData(string FilePath) {
     int Selection = 0;
     foreach (string item in RAM) {
         if (item == RAMFileFormatHeader && RAM[Selection + 1] == FilePath) {
             SaveFile(RAM[Selection + 1], GetData(RAM[Selection + 1]));
         }
     }
 }

What is happening is that when I go into debug and look at what files were "successfully saved"... The only file that is saved is "Settings.txt", and none of the others (like "GameData.txt, which is constantly updated to a string that does not match what's on the file)

Any and ALL help appreciated...

If need be, I can post my other custom voids or functions if you need, incase it is any of those

Comment
Add comment · Show 8
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 Glurth · Jan 07, 2017 at 06:30 PM 0
Share

All you functions are using a variable called RA$$anonymous$$, a string array I think: but we don't see how this array is being filled. To assume it is populated correctly, might be mistake.

avatar image Creeper_Math Glurth · Jan 07, 2017 at 06:50 PM 0
Share

I have the RA$$anonymous$$ going to a debug ram also, which that is being filled properly

Video Demonstrating that it is being filled correctly

avatar image Glurth Creeper_Math · Jan 07, 2017 at 07:07 PM 1
Share

Hmm. I see you are calling parse int, on a string of a floating point number. (in the video a floating point number always follows the filename/path) perhaps you meant to use float.TryParse ?

Then it gets confusing: I see you using the length of that parsed string to create a new array of empty strings (but is otherwise ignored). Did you mean to use a FOR loop here? e.g.

 for(int Selection1=0;Selection1< length; Selection1++)

I don't see the code for Command.AddString, perhaps that's where the problem lies? I generally use List< sting> rather than an array, string[], if I'm not sure how long I want it to be. Adding items to a list is much easier. (https://msdn.microsoft.com/en-us/library/3wcytfd1(v=vs.110).aspx)

Show more comments

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

267 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 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 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

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Using static variables (or similar) to affect instances of the same object separately. 2 Answers

Unity does not finish write file (filecontent suddenly ends) 1 Answer

How to make it so Unity remembers purchases made by players whenever they play? (C#) 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