- Home /
Comparing the contents of two arrays for specific value
So I'm creating a combat system where each combatant has a score that says when they go in combat. There turn basically. I have three arrays for sorting these numbers to determine when a character may act. So far it works. Sort of. Anytime I sort the array and then have my function to place the player in the sequence of when they go if I have a value that is reoccurring then it simply places them as the same place as the character before them. So let's say two characters roll a 6, then both characters will be placed at say spot 2. Which means when I advance the combat rounds one of the characters will be skipped. Here is the code that is causing the error. Any help would be appreciated.
The problem I believe lays in the SortInitativeArray() function but I have been unable to solve it despite researching and what not.
//sort the array from lowest to highest
Array.Sort(_initativeTracker);
// reverse array from highest to lowest
Array.Reverse(_initativeTracker);
for (int i = 0; i < _totalCombatants; i++)
{
SortInitativeArray(i);
}
}
public void SortInitativeArray(int index)
{
for (int i = 0; i < _totalCombatants; i++)
{
if (_initativeTracker[i].Equals(tempInitativeTracker[index]))
{
finalInitativeTracker[i] = initativeCounter;
initativeCounter++;
return;
}
}
}