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 DarkSlash · Jan 04, 2012 at 03:46 PM · arrays

Multidirectional arrays on javascript

Ok, Unity 3.4 has support for multidirectional arrays on JS. But Im having troubles initializing them. Here's my example:

var myArray : Array;

function Start() { myArray = new Array(); myArray[0][0] = 1; myArray[0][1] = 2; myArray[2][3] = 3; myArray[2][4] = 4; myArray[3][0] = 5; }

But when I try to use it it seems to be empty. What Im doing wrong?

Console Error: "ArgumentOutOfRangeException: Index is less than 0 or more than or equal to the list count."

Thanks!

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

2 Replies

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

Answer by Eric5h5 · Jan 05, 2012 at 06:35 PM

You mean "multidimensional", not "multidirectional". Array is obsolete and pretty much shouldn't ever be used. Use built-in arrays or Lists instead. A multidimensional array is declared like this:

 var myArray : int[,];
 
 function Start () {
     myArray = new int[4,4];
     myArray[0,0] = 1;
     myArray[0,1] = 2;
 }
Comment
Add comment · Show 7 · 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 DarkSlash · Jan 05, 2012 at 06:43 PM 0
Share

Thanks for the clarification! ArrayLists is what you are telling me to use?

And thanks for the correction! Lost on translation! ;)

avatar image softrare · Jan 05, 2012 at 06:44 PM 0
Share

If we talk about not using things I would also mention "JavaScript" for Unity scripts. Take an hour and make yourself comfortable with C# :) It helps a lot keeping the code clean and readable.

avatar image DarkSlash · Jan 05, 2012 at 06:52 PM 0
Share

This is my first project. The second one will be on C#. Thanks! :)

avatar image Eric5h5 · Jan 05, 2012 at 06:53 PM 0
Share

No, not ArrayList, they are just as obsolete as Array. You can use generic Lists if you need resizable arrays, otherwise standard built-in arrays are fine. @softrare: that's a matter of opinion, and personally I find Unityscript cleaner and easier to read for the most part. C# tends to be sometimes obtuse and unnecessarily fiddly, and not as well integrated into Unity (which is understandable, since Unityscript is custom made for Unity).

avatar image Fattie · May 31, 2012 at 11:41 AM 0
Share

@Eric5x5, I now only use List since you told me to.

But in fact ........... I'm wondering, what do you recommend for 2-dimensional use, here in the Unity universe? (Let's say, we know in advance the fixed length of each dimension; and what if we don't). Thanks.

Softare .. Eric is right and you are wrong on this one. To phrase it highly offensively - and why not> this is the internet after all - only someone who is not a real programmer would find c# better than UnityScript. As far as program$$anonymous$$g languages go, they are both a laughable idiotic bizarre stupid joke. (In fairness, i think the same thing about every program$$anonymous$$g language and environment I've been forced to use.) And as Eric states, UnityScript is far more "integrated" with U3D. You could put it this way: I$$anonymous$$O a preference for C# is naive. This message brought to you by Flame War Central! :-)

incidentally ....... is your nickname (softare) an incredibly clever reference to the archaic measure of 2D space in mideuropean languages?? If so, you have the cleverest nickname on the system.

Show more comments
avatar image
2

Answer by softrare · Jan 04, 2012 at 03:51 PM

does that work?

 var myArray : Array;
 
 function Start() { 
     myArray = new Array(); 
     myArray[0] = new Array();
     myArray[0][0] = 1;     
     myArray[0][1] = 2;
     myArray[2] = new Array();
     myArray[2][3] = 3; 
     myArray[2][4] = 4; 
     myArray[3] = new Array();    
     myArray[3][0] = 5; 
 }
Comment
Add comment · Show 3 · 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 DarkSlash · Jan 05, 2012 at 06:01 PM 0
Share

That works perfectly! It's not a multidirectional array, is an array of arrays, but it works fine! Thanks!

avatar image softrare · Jan 05, 2012 at 06:39 PM 0
Share

Not a problem :) to be a smart ass once more: it's a multi"dimensional" array ^^

avatar image softrare · Apr 05, 2012 at 03:02 PM 0
Share

if I resolved your question please mark my answer accordingly (solved) :)

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

6 People are following this question.

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

Related Questions

Best way to keep track of objects on a 3D Grid? 2 Answers

How to return the position of an object in a 2 dimensional array 1 Answer

How to debug values in jagged arrays? 0 Answers

IndexOutOfRangeException for initial spawn of prefabs from an array 1 Answer

Implementing a 2D array as a field on a ScriptableObject? 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