Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by unity_uBC5av1p4gX0jg · Jun 20, 2021 at 08:15 PM · errorargumentoutofrangeexception

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;
                     }
 
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

200 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

ArgumentOutOfRangeException: Argument is out of range. Parameter name: index 1 Answer

I am getting an error : ArgumentOutOfRangeException: Argument is out of range. Parameter name: index 0 Answers

Argument out of Range Exception Error. [Basic] 0 Answers

Why do all of my scripts say "No MonoBehavior scripts in the file, or their names do not match the file name?" 1 Answer

Animator().Play is not accepting variable 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges