   (C#/XNA) Reading from a Text file
  Hey Gamedev.net. Little problem here. I recently decided I wanted to try out reading in information from text files to make my future games more customizable or whatever other uses it may have. Sadly, I can't quite get it to do what i want it to do.public Player(string path, ContentManager Content)   {  position = Vector2.Zero;  List<string> lines = new List<string>();  using (StreamReader reader = new StreamReader(path))  { string line = reader.ReadLine(); while (line != null) {lines.Add(line);line = reader.ReadLine(); } foreach (string s in lines) {if (s.StartsWith("Texture")){    s.Remove(0, 8);    texture = Content.Load<Texture2D>(s);} }  }   }Here's what I have so far. All this is supposed to do is get the player's texture from a file that I pass to it. It's read in all right, the only problem is that the text file says "Texture player.png". The first 8 chars are supposed to be redacted so that the Content.Load call only gets "player.png". . . which it doesn't do. I'm probably just misunderstanding the behavior of the Remove function or something, because the error I get just tells me Error loading "Texture player.png". File not found.Which tells me it's getting the string in fine, it's just not removing the first part of the string like I want it to. Any help would be more than appreciated.   
  Hi,problem is that you don't assign new string at string.removeex. newString = s.remove(0,8);or you can set without s.remove(0,8);texture = Content.Load<Texture2D>(s.remove(0,8));bye.   ;  Thank you very very much. I suppose it was just me misunderstanding the behavior of s.Remove(). I thought that it removed those chars from the string itself, and kept them gone or whatever, you know what I mean. Thanks for the help, it works fine now.   ;  Well done.this is a good way ... but you should use a xml file.example: node "Texture Player" text1.png text2.png    node "Texture World" worldtext.pngetc..etc..   ;Quote:Original post by luchettoWell done.this is a good way ... but you should use a xml file.example: node "Texture Player" text1.png text2.png    node "Texture World" worldtext.pngetc..etc..Hmm, could you maybe explain the actual benefits of XML over plain-text? I don't really feel the desire to learn a new 'language'(or whatever you call XML) if I don't get a noticeable return on investment.   ;  Hi,if you want to develop the game for XBOX you have to use XML. moreover, if thought well, you can use it as a mini db.   ;  Okaaay. . . . tell me how I use it then. It's all HTML-flavored greek to me.   ;  This is a example of data on xml file. this is basis idea.. you read tutorials on web o MSDN and understand all.<?xml version="1.0"?><ArrayOfTestData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">  <TestData>    <ID>1</ID>    <Team>Cosenza</Team>    <Strenght>60</Strenght>  </TestData>  <TestData>    <ID>2</ID>    <Team>Juventus</Team>    <Strenght>85</Strenght>  </TestData>  <TestData>    <ID>3</ID>    <Team>Milan</Team>    <Strenght>88</Strenght>  </TestData></ArrayOfTestData>for read you must // Open a storage container.StorageContainer container = storageDev.OpenContainer("GameData");// Get the path of the data game.string filename = Path.Combine(container.Path, "example.xml");// Check to see whether the data exists.if (!File.Exists(filename))  // Notify the user there is no data. return;// Open the file.FileStream stream = File.Open(filename, FileMode.Open, FileAccess.Read);// Read the data from the file.XmlSerializer serializer = new XmlSerializer(typeo(List<TestData>));td = (List<TestData>)serializer.Deserialize(stream); // Close the file.stream.Close();// Dispose the container.container.Dispose(); ;Quote:Original post by luchettoThis is a example of data on xml file. this is basis idea.. you read tutorials on web o MSDN and understand all.<?xml version="1.0"?><ArrayOfTestData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">  <TestData>    <ID>1</ID>    <Team>Cosenza</Team>    <Strenght>60</Strenght>  </TestData>  <TestData>    <ID>2</ID>    <Team>Juventus</Team>    <Strenght>85</Strenght>  </TestData>  <TestData>    <ID>3</ID>    <Team>Milan</Team>    <Strenght>88</Strenght>  </TestData></ArrayOfTestData>for read you must // Open a storage container.StorageContainer container = storageDev.OpenContainer("GameData");// Get the path of the data game.string filename = Path.Combine(container.Path, "example.xml");// Check to see whether the data exists.if (!File.Exists(filename))  // Notify the user there is no data. return;// Open the file.FileStream stream = File.Open(filename, FileMode.Open, FileAccess.Read);// Read the data from the file.XmlSerializer serializer = new XmlSerializer(typeo(List<TestData>));td = (List<TestData>)serializer.Deserialize(stream); // Close the file.stream.Close();// Dispose the container.container.Dispose();Yeah. . . I don't understand what ANY of that means. ;Quote:Original post by luchettoif you want to develop the game for XBOX you have to use XML. That is incorrect. You can use plain text files just fine on the Xbox 360. You can copy them with your game (add them in VS and set them to Copy If Newer) and you can save/load them using the StorageContainer APIs. There is nothing on the platform that forces you into XML.   