using (StreamReader sr = new StreamReader(layerFile))
//using (StreamReader sr = new StreamReader("Content/levels/" + map + "/layer1.txt"))
{
string line;
int[,] partsArray = new int[(int)mapsize.X, (int)mapsize.Y];
int partCounter = 0;
int lineCounter = 0;
while ((line = sr.ReadLine()) != null)
{
string[] parts = line.Split(',');
//build the parts array
for (int rowWidthCounter = 0; rowWidthCounter < line.Length/2; rowWidthCounter++)
{
partsArray[lineCounter, rowWidthCounter] = Convert.ToInt32(parts[partCounter]);
partCounter++;
}
lineCounter++;
partCounter = 0;
}
//layer1 = partsArray;
holderLayer = partsArray;
switch (layerNum)
{
case 1: layer1 = holderLayer; break;
case 2: layer2 = holderLayer; break;
default: break;
}
}
This works fine loading from a file in this format:
1,1,1,1,1,1,1,1,1,1,1, 1,1,1,6,7,1,1,1,1,1,1, 1,1,1,8,9,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,
As long as the number between ,'s is 0 - 9 then it all works fine, i can even add a double digit number to a line, but if i try to add two double didgit numbers to a line like:
1,1,1,1,1,1,1,1,1,1,1, 1,1,1,6,7,1,1,1,1,1,1, 1,1,1,8,9,1,1,1,1,1,1, 1,1,1,10,11,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,
then i get this error:
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll Input string was not in a correct format.
and i have no idea why. =[

New Topic/Question
Reply



MultiQuote



|