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 /
avatar image
0
Question by Jenkins6161 · Sep 20, 2013 at 10:25 PM · javascriptlistgenericsargumentoutofrangeexception

JS Argument out of range

Getting this error: ArgumentOutOfRangeException: Argument is out of range. Parameter name: index

Been trying to get this to work for a few days now. Heres my code: This is my Stage class

 import System.Collections.Generic;
 
 class Stage
 {
     var controlArray: String[];
     var taskName: String[];
     var taskStatus: Texture2D[];
     var PC: boolean;
     var arrowArray: GameObject[];
 }

and this is my script that handles actually putting it up on the GUI

 static var Stages : List.<Stage> = new List.<Stage>(22);

 function Start() {
   var Stage0 = new Stage();
   Stage0.controlArray = new String[2];
   Stage0.arrowArray = new GameObject[4];
   Stage0.controlArray[0] = "";
   Stage0.PC = false;
   Stage0.arrowArray[0] = null;

   //...truncated

   var Stage16 = new Stage();
   Stage16.controlArray = new String[2];
   Stage16.taskName = new String[6];
   Stage16.taskStatus = new Texture2D[6];
   Stage16.arrowArray = new GameObject[4];
   Stage16.controlArray[0] = "";
   Stage16.taskName[0] = "findTheWaterCooler";
   Stage16.taskName[1] = "returnToYourDesk";
   Stage16.taskName[2] = "dropToTheGround";
   Stage16.taskName[3] = "coverUnderTheDesk";
   Stage16.taskName[4] = "holdDuringTheEarthquake";
   Stage16.taskName[5] = "dustYourselfOff";
   Stage16.taskStatus[0] = Resources.Load("check_box_checked");
   Stage16.taskStatus[1] = Resources.Load("check_box_failed");
   Stage16.taskStatus[2] = Resources.Load("check_box_checked");
   Stage16.taskStatus[3] = Resources.Load("check_box_checked");
   Stage16.taskStatus[4] = Resources.Load("check_box_checked");
   Stage16.taskStatus[5] = Resources.Load("check_box_empty");
   Stage16.PC = false;
   Stage16.arrowArray[0] = null;

   Stages[0] = Stage0;

   //...truncated

   Stages[21] = Stage21;
 }

 function OnGUI() {
     GUI.skin=skin;
     for (var i: int = 0; i < 22; i++)
     {
         if (GC.GetComponent(NewGC).stage==i) {
             Debug.Log(Stages[i].taskName[0]);
             if ((Stages[i].taskName[0]!=null)&&(Stages[i].taskStatus[0]!=null)) {
                 showTask(Stages[i].taskName[0], Stages[i].taskStatus[0], 1);
             }

             //...truncated

             if ((Stages[i].taskName[5]!=null)&&(Stages[i].taskStatus[5]!=null)) {
                 showTask(Stages[i].taskName[5], Stages[i].taskStatus[5], 6);
             }
         }
     }
 }

ArgumentOutOfRangeException: Argument is out of range. Parameter name: index System.Collections.Generic.List`1[Stage].get_Item (Int32 index) (at /Applications/buildAgent/work/c514da0c8183631c/mcs/class/corlib/System.Collections.Generic/List.cs:633) tasks.OnGUI () (at Assets/Scripts/tasks.js:285)

Its having a problem at line 46 with 'Debug.Log(Stages[i].taskName[0]);' particularly the Stages[i]

What am I doing wrong??

Comment
Add comment · Show 1
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
avatar image robertbu · Sep 21, 2013 at 03:55 AM 0
Share

If you double click on the error, what line of code is triggering the error? Also can you past in the error message?

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by DaveA · Sep 21, 2013 at 08:02 AM

You are trying to initialize a lot of stuff outside of a Start function. And you have not allocated the arrays. For example:

 function Start()
 {
 var Stage16 = new Stage();
 Stage16.controlArray = new String[6]; // add this
 Stage16.taskName = new String[6]; // add this
 Stage16.controlArray[0] = "";
 Stage16.taskName[0] = "findTheWaterCooler";
Comment
Add comment · Show 5 · Share
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
avatar image Jenkins6161 · Sep 21, 2013 at 06:47 PM 0
Share

Updated code in OP.$$anonymous$$oved Stage initialization to start function and added the array initialization like you said. Still getting the same error.

avatar image DaveA · Sep 21, 2013 at 07:03 PM 0
Share

Same line? different line?

avatar image Jenkins6161 · Sep 21, 2013 at 07:06 PM 0
Share

yes same line. Its having issues with the list not the stages themselves as far as i can tell

avatar image DaveA · Sep 21, 2013 at 07:07 PM 0
Share

Also this:

 static var Stages : List.<Stage> = new List.<Stage>(22);

like

 static var Stages : List.<Stage>;

 Start()
 {
    Stages = new List.<Stage>(22);
avatar image Jenkins6161 · Sep 21, 2013 at 07:17 PM 0
Share

\o/ not getting the arugement error anymore! Now im getting NullReferenceException: Object reference not set to an instance of an object tasks.OnGUI () (at Assets/Scripts/tasks.js:292) for same line :/

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

16 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

Related Questions

Insert a string to a list inside a list 3 Answers

Can you define a jagged Generic List in UnityScript? 1 Answer

A node in a childnode? 1 Answer

How to add to a list excluding certain items 1 Answer

How to transform arrays into easier to edit list (JS) 3 Answers


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