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 · Dec 18, 2016 at 11:24 AM · c#arraysstringdatadata storage

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)

Comment
Add comment · Show 4
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 Creeper_Math · Dec 22, 2016 at 06:36 PM 0
Share

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

avatar image jmgek Creeper_Math · Dec 22, 2016 at 07:53 PM 0
Share

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.

avatar image Creeper_Math jmgek · Dec 22, 2016 at 08:04 PM 0
Share

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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

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

Convert string to guitext, in a guitext array. 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