- Home /
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
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.
I have the RA$$anonymous$$ going to a debug ram also, which that is being filled properly
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)
Your answer
Follow this Question
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