Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 dansav · Aug 02, 2011 at 06:42 PM · arrayuce0001multidimarraybce0048

trouble with 2 dimensional arrrays in javascript

I am having trouble declaring and using a 2 dimensional array in javascript using unity 3.3

 var x2: int[,]; no error but then errors later  
 var x2:int[5,5]; //error excpecting semicolon at the end.
 
 x2[4][4]=0;  
     
 Debug.Log(x2[4][4]); //error BCE0109: Array 'self.x2' is rank '2', not rank '1'.and
                        type int does not support slicing.

So many errors? I'm following examples other people have posted about the multidimensional arrays in javascript in 3.2

Any ideas? thanks Dan

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 Eric5h5 · Aug 02, 2011 at 08:41 PM 0
Share

Please don't cross-post both here and on the forums.

1 Reply

· Add your reply
  • Sort: 
avatar image
3

Answer by SilverTabby · Aug 02, 2011 at 08:11 PM

Javascript 2d arrays are tricky. I ended up looking up C# 2d arrays and then moved the syntax to javascript and it worked. Here's what I found worked:

 var myArray : int[,] = new int[5,5];
 myArray[0,1] = 42;
 for(var X : int = 0; X < myArray.Length(0); X++)
     for(var Y: int = 0; Y < myArray.Length(1); Y++)
     {
         myArray[X,Y] = X+Y;
         Debug.Log(myArray[X,Y]);
     }

That should be all the information you need to work with and loop through 2d arrays.

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 dansav · Aug 03, 2011 at 06:35 PM 0
Share

Yep. That works. They should update the docs under arrays with your suggestions about how to use them.

avatar image Fattie · Jun 02, 2012 at 02:30 PM 0
Share

Fascinating that the "length" is a kind of a function across the dimensions!! Would never have guessed, and it's totally undocumented of course. Cheers.

avatar image Jason-King · Mar 11, 2013 at 06:32 PM 0
Share

The length calls in unityscript gives me... BCE0077: It is not possible to invoke an expression of type 'int'. What's up with that?

avatar image Eric5h5 · Mar 11, 2013 at 08:48 PM 0
Share

It should get GetLength, not Length.

avatar image Jason-King · Mar 11, 2013 at 10:13 PM 0
Share

Thanks Eric5h5! GetLength compiles. But where is that documented? Even after knowing the proper semantics, I'm having trouble finding a definitive entry within language docs. I assume there may be other functionality attached to multidimensional arrays. Where can I find the complete set available to unityscript?

Show more comments

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

7 People are following this question.

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

Related Questions

Error with Array declaration 1 Answer

Access specific GameObject in arrays 1 Answer

How to declare and initialize multidimensional arrays JS? 4 Answers

Vector 3 in array 1 Answer

How to declare a multidimensional array of strings in c#? 2 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