- Home /
My custom function for Updating a data string in an array causes deletion of all other data
I have a "gamedata" string array that on the game start is filled with all data currently stored on a text file, which completely works. I have this script that would update, or add if there wasn't any, a section of data (inputted as a string[] ) into the game array. What seems to be happening is that only ONE of the data that I have using this script is being used (I believe it's deleting the other data because whenever I manually input the other data it just removes it). I do use some custom scripts / commands in the command script
Goal of the script -> Take an array with a specific name, and update the existing data into the gamedata array, or add it if there is none already, starting with a bunch of dashes with the name and ending with the save bunch of dashes
Command.ArrayAddString(string[] arraystring, string objecttoad); // This works fine, I have proven it to work multiple times. All it does is add an item to an array
endmark is just a bunch of dashes "------------" as well as the startmark
public static void UpdateGameData(string[] Data, string DataName) {
debugupdatestuff += 1;
string StartName = StartMark + DataName;
string[] Return = new string[0];
bool FoundStart = false;
bool FoundLast = false;
int Start = 0;
int End = 0;
int Selection = 0;
// Find the start and end of the data if the data is already in the string array
foreach (string item in GameData) {
if (FoundStart == false && item == StartName) {
FoundStart = true;
Start = Selection;
}
if (FoundStart == true && FoundLast == false && item == EndMark) {
FoundLast = true;
End = Selection;
}
Selection += 1;
}
Selection = 0;
// find all the data *not* in the range between the start and end and put it into an array
string[] ExtractedData = new string[0];
if (FoundLast == true) {
foreach (string item in GameData) {
if (Selection < Start) {
ExtractedData = Command.ArrayAddString(ExtractedData, item);
DebugLogging.Log(debugupdatestuff.ToString() + " added item" + item);
}
if (Selection > End) {
ExtractedData = Command.ArrayAddString(ExtractedData, item);
DebugLogging.Log(debugupdatestuff.ToString() + " added item" + item);
}
Selection += 1;
}
}
// Set the gamedata to all the places above, in essence removing the data input that we want to update
GameData = ExtractedData;
// Adding the data we want to update (updated data) to the end
GameData = Command.ArrayAddString(GameData, StartName);
foreach (string item in Data) {
GameData = Command.ArrayAddString(GameData, item);
}
GameData = Command.ArrayAddString(GameData, EndMark);
}
Here is what the data SHOULD come out with
----------Player Location
2.061744
11.5
6.801244
----------
----------Player Health
500
----------
And here's what its actually coming out to
----------Player Health
500
----------
Note that the player location is executed BEFORE the player health
I do know that all my other scripts are in working condition so I'm almost confident that this is what's not working
I also don't want to really go into the list format because if I did, it would need to be converted back to a string array before this script ends... I don't know anything about lists or other too too *complex things (although I am able to learn with enough effort)
Ok.... Well I had re-written the entire script as noone responded for some days and I do have a working script.. Later today I can upload it here if anyone wants to see it..
We would love to help you but if you could try to keep your code as small as possible so we're not sifting through 100 lines trying to figure out the problem, on top of reading 4 paragraphs of text.
Try and keep the scope to what you're having the problem with, try to stay away from copy pasting your code you have, and limit your functions to what you need.
Ok.. I will remember that when I ask any other questions.. It's just that I didn't know which section was giving the problem...
Your answer
Follow this Question
Related Questions
Changing a GUI String to read as a INT 2 Answers
Get value from string and pass it to another field 0 Answers
Fastest C# Byte[] to String conversion? 1 Answer
Distribute terrain in zones 3 Answers