I am writing a function that iterates through string[] array and adds some objects into lists. It is a part of loading saved game system. It has a lot of buggs yet, because I wrote a lot of code, before can test any of it. But in this debugging phase I found some weird bug, that am not able to explain or fix.
I cant access some of data. If I have original code, for-loop iterates 1 time less then needed. If I add +1 to iterator limit, it acts normally. To conclude, I can iterate either -1 or +1 times, but not as much as I need.
This is the original code, which iterates one time less than expected:
string str = " start at " + Convert.ToInt32(s[k]) + " " + k;
for (int i = 0; i < Convert.ToInt32(s[k]); i++)
{
k++;
landOwned.Add(setle.civil.land[Convert.ToInt32(s[k]), Convert.ToInt32(s[k+1])]);
k++;
str += " iteration "+i + " finish " + k;
}
throw new ArgumentException(str);
This is the line in text file:
f 4894 0 250 -523058 0 0 0 0 0 0 0 0 0 0 0 0 0 35 35 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 3 4 2 4 3 3 4 4 1 0 1 0 1 0 1 2
Here are screenshots of exeptions catched: