I had a List that added all available to it, without parameters, because of the way my map loads. So a cheap fix I thought to just iterate through the list, and remove any indexes that weren’t in new parameters.
I remember talking about this before, ages ago, and someone told me to just invert the “for loop” so that it counts down from list.Count and that would fix any issues with skipping over indexes.
But before I wrote that out I decided to test this:
void FixAdjacent()
{
for (int i = 0; i < adjacentHex.Count;)
{
if (adjacentHex[i].myType != TypeOfHex.Land)
{
adjacentHex.RemoveAt(i);
}
else { i++; }
}
fixedList = true;
}
And through all my testing, this seems as though it works just fine. Which is weird, because I thought for loops could only be setup the standard way.
So just to double check, is this method ok to use? Or is it possible it can glitch out? Or is there any opinions of a possible better way?