Argument Out of Range Exception: Error with Array Turned into List
I made a 2D array and turned the second row into a list so I could use the RemoveAt function without affecting the original 2D array given that it is used throughout the code for other things. The goal is to fill the text of the UI buttons with text from the 2D array but, to make sure there's not repeating text, I turned the array into a list so I could remove the strings from the list as they're loaded into the buttons. Whenever I run the game though, I keep on getting an error that says "ArgumentOutOfRangeException: Argument is out of range. Parameter name: index" at the line "avatarRandArray2[j] = avatarArray[1, j]; " Any thoughts on how to go about fixing this? Also, there is code missing in between the initialization of the 2D array and the if statement. It's just a very long code and didn't want to force you guys to read everything. If it seems like it may be needed, just let me know, it shouldn't be related though.
//Start Familiarization Task
string[,] avatarArray = new string[2, 14]
{
{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13"},
{AvatarFacts[0], AvatarFacts[1], AvatarFacts[2], AvatarFacts[3], AvatarFacts[4], AvatarFacts[5], AvatarFacts[6], AvatarFacts[7], AvatarFacts[8], AvatarFacts[9], AvatarFacts[10], AvatarFacts[11], AvatarFacts[12], AvatarFacts[13] }
};
string[,] furnitureArray = new string[2, 14]
{
{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13"},
{FurnitureFacts[0], FurnitureFacts[1], FurnitureFacts[2], FurnitureFacts[3], FurnitureFacts[4], FurnitureFacts[5], FurnitureFacts[6], FurnitureFacts[7], FurnitureFacts[8], FurnitureFacts[9], FurnitureFacts[10], FurnitureFacts[11], FurnitureFacts[12], FurnitureFacts[13] }
};
//start of quiz
if (condition == 0)
{
for (int i = 0; i < avatarArray.GetLength(1); i++)
{
ScoreDisplayText.text = "Score:0";
for (int j = 0; j < avatarArray.GetLength(1); i++)
{
avatarRandArray2[j] = avatarArray[1, j];
}
for (int j = 0; j < AnswerButtons.Length; j++)
{
ButtonManager.gameObject.SetActive(true);
}
avatarFactDisplay.text = "What does " + avatarsQuiz[Convert.ToInt32(avatarArray[0, i])].name + "like to do? ";
isCorrect = i;
string correctText = furnitureRandArray2[isCorrect];
for (int j = 0; j < AnswerButtons.Length; j++)
{
if (j == 0)
{
AnswerButtons[j].GetComponentInChildren<Text>().text = avatarRandArray2[isCorrect];
avatarRandArray2.RemoveAt(isCorrect);
}
else
{
int randomAvatar = UnityEngine.Random.Range(0, avatarRandArray2.Count);
string randomFact = avatarRandArray2[randomAvatar];
AnswerButtons[j].GetComponentInChildren<Text>().text = randomFact;
avatarRandArray2.RemoveAt(randomAvatar);
}
int randomButton = UnityEngine.Random.Range(0, AnswerButtons.Length);
AnswerButtons[j] = AnswerButtons[randomButton];
}
AnswerButtons[0].onClick.AddListener(ButtonClicked);
AnswerButtons[1].onClick.AddListener(ButtonClicked);
AnswerButtons[2].onClick.AddListener(ButtonClicked);
AnswerButtons[3].onClick.AddListener(ButtonClicked);
yield return StartCoroutine(WaitForAnswer());
answerChosen = false;
}