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 Clonkex · Aug 24, 2014 at 12:37 PM · javascriptarraymultidimensional array

How to Create Multidimensional Array in Javascript?

I realise this question has been asked before, but I was unable to find any answer relating to the latest version of Unity except these two, which offer two different solutions, and I'm not sure which is correct:

http://answers.unity3d.com/questions/11963/how-to-create-multidimensional-arrays-in-javascrip.html http://answers.unity3d.com/questions/222522/multidimensional-array-in-javascript.html

So, using Unity 4.x, how would I create a multidimensional (specifically, 3D) array of classes?

As a bonus question, is it possible to create this 3D array as a dynamic array of some sort, so I can change the size dynamically?

EDIT: If I use the following code to create the array, how then would I set the size or add new elements?

 var bricks:int[,,];



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

1 Reply

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

Answer by Tonyx97 · Aug 24, 2014 at 02:40 PM

The correct way to create a multiarray on JS is like this:

 var multiArray:int[,,];

or if you have to define the length of the multiArray when scripts starts you can use:

 private var multiArray:int[,,] = new int[10,10,10];

when says new int[10,10,10] means that you can put 10 3d integers, 10 like this 56,3,22.

Comment
Add comment · Show 4 · 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 Clonkex · Aug 24, 2014 at 10:23 PM 0
Share

Perfect! Thankyou. Only- If I do want to add elements later without defining the length immediately, how would I do that?

avatar image Tonyx97 · Aug 25, 2014 at 08:33 AM 0
Share

I have a little error on the last answer, it wasn't multiArray[10,10,10], the correct way is multiArray[10,10,10,10] because in the index number 1 you have to put 3 variables more, so for defining is multiArray:int[,,,] . You can use for example, to put a 3d coordinates you have to:

 multiArray[0,0,0,1] = 1;
 multiArray[0,0,1,0] = 5;
 multiArray[0,1,0,0] = 3;

This means, that in the index 0 will be 3 coordinates.

avatar image Clonkex · Aug 26, 2014 at 01:28 PM 0
Share

You know you can edit a post, right?

avatar image Clonkex · Aug 26, 2014 at 01:33 PM 0
Share

Also - what? I'm not looking to store 3D coordinates like that, but rather access a 3D array by 3D coordinates. So, I would do this:

 class thingclass
 {
     var randomdata:int;
 }
 
 var thing:thingclass[,,];
 
 function Start()
 {
     thing[1,5,3].randomdata=42;
 }

$$anonymous$$y problem is still how I would set the size of the array if I don't define it when I create it (because I don't think the above code is actually valid).

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

24 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

Related Questions

Multidimensional array variable size (JS) 1 Answer

How to Add Elements to Size-Undefined Multidimensional Array in Javascript? 0 Answers

How to Create Dynamic Multidimensional Array? 1 Answer

Physics.OverlapSphere with a min radius? 1 Answer

Newbie Problem with Multidimensional Arrays in JavaScript 0 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