   [C#][SDL.Net]Loading maps
  Hello there! I'm new to this forum and I've found it with google. =PAnyway, I've always wondered how to load maps... 2D maps with tiles... Anyway, here's my try at it with C# and SDL.Net :using System;using System.IO;using System.Drawing;using SdlDotNet.Graphics;using SdlDotNet.Core;using SdlDotNet.Audio;using SdlDotNet.Graphics.Primitives;using SdlDotNet.Graphics.Sprites;using SdlDotNet.Input;using SdlDotNet.Particles;using SdlDotNet.Windows;namespace Contra2012{    class Map    {   private Rectangle m_source;   private SpriteCollection m_spritecollection;   private Sprite m_sprite;   private StreamReader m_data;   private int m_offsetx;   private int m_offsety;   private int m_value;   private int m_tile;   private int m_line;   private string m_current;   public void Initialize(string surface, string data)   {  m_data = File.OpenText(data);  while (!m_data.EndOfStream)  { m_current = m_data.ReadLine(); for(int i = 0;i < m_current.Length;i++) {for (int u = 0; u < m_current.Length; u += 1){    if (m_current != '(' || m_current != ',' || m_current != ')' && i+u&lt;m_current.Length)   m_value += (int)m_current<span style="font-weight:bold;"> + u * 10;    else   break;}if (m_current<span style="font-weight:bold;"> == ',')    m_offsetx = m_value * 16;if(m_current<span style="font-weight:bold;"> == ')'){    m_offsety = m_value * 16;    m_sprite = new Sprite(new Surface(surface), new Point(m_tile * 16, m_line * 16), m_spritecollection);    m_sprite.Surface.ClipRectangle = new Rectangle(m_offsetx,m_offsety,16,16);    m_spritecollection.Add(m_sprite);} } m_line ++;  }   }    }}</code>The format of the text files : (#th of the tile in the spritesheet &#111;n the X axis,#th of the tile in the spritesheet &#111;n the Y axis)(1,0)(2,4)(2,3)But I can't seem to make it work. It said that my Index is going outside the limits…I don't mind rewriting all of the stuff, so if there is a better way to do so,say it to me. ;)Thanks.Ps.I hope there isn't too much code to look at. =P
  You got two nested loops walking through the same string, and you are adding those indexes together. Something fishy about that.Instead of trying to identify the problem I wrote another parsing function that I think is clearer and less prone to errors. I don't have SDL installed for C# so I'm just gonna extract the coordinates and print them to the screen.public void Initialize(string surface, string data){    m_data = File.OpenText(data);   char[] separators = { ',', '(', ')' }; // Adding all characters we consider meta-data    while (!m_data.EndOfStream)    {   m_current = m_data.ReadLine();   // Creating an array of strings, removing ( ) and ,   string[] pairs = m_current.Split(separators, StringSplitOptions.RemoveEmptyEntries);   // Making sure that there is at least two coordinates, and that the number of coordinates found is an even number   if (pairs.Length < 2 || (pairs.Length % 2) != 0)   {  Console.WriteLine("Something is wrong with the file format");  return;   }   // Walking through all the coordinate pairs   for (int i = 0; i < pairs.Length; i += 2)   {  // Extracting the x and y values, and removing white spaces  string sx = pairs.Trim();  string sy = pairs[i+1].Trim();   // Converting the values into 32 bit integers  int x = Convert.ToInt32(sx);  int y = Convert.ToInt32(sy);  // Do whatever you want to the coordinates here, I'm just gonna print them to screen for convenience  Console.WriteLine(x.ToString() + " " + y.ToString());   }} };  This looks great! I will try it out tomorrow and see if I can make it work it out.Thanks for the input. ;)   