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 RandomMeasure · Jul 26, 2010 at 03:24 PM · passingmultidimarray

Passing a Multidimensional array in Javascript

I have constructed multidimensional array in javascript using the MultiDim.cs script. I would now like to be able to pass the array to a function in another class without having to break it down to a single dimensional array and then rebuild it in the other class. What would be the proper typing to insert into the "function something( multiDimArray : Type )" in order to pass the array, if it's possible?

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

3 Replies

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

Answer by Mike 3 · Jul 26, 2010 at 04:20 PM

I would make a script containing the below:

class MultiDimContainer { var multiDim;

 function MultiDimContainer(originalMulti)
 {
     multiDim = originalMulti;
 }

 function Get()
 {
     return multiDim;
 }
 /*  //this setter function is optional, for changing the array in the container  after creation
 function Set(newMultiDim)
 {
     multiDim = newMultiDim;
 }
 */

}

What you would then do is something like this to use it:

//calling site var multiDimContainer = new MultiDimContainer(yourMultiDimArray); YourFunction(multiDimContainer);

//the called function function YourFunction(multiDimContainer : MultiDimContainer) { //do something with MultiDimContainer.Get(); }

Comment
Add comment · Show 1 · 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 RandomMeasure · Jul 26, 2010 at 06:45 PM 0
Share

I ultimately did something similar. After some experimentation I realized that all I had to do was declare the variable and then define it in the constructor and I could simply access the variable by passing the object around. Thanks for the response!

avatar image
1

Answer by Eric5h5 · Jul 26, 2010 at 06:22 PM

Edit: this is outdated in Unity 3.2. You can just use 2D arrays in JS now.

You can't declare the correct type in this case, which is why the MultiDim workaround exists in the first place. You can leave out the type, which makes a dynamic variable. This variable itself won't work with multi-dimensional syntax, but you can declare another local variable in the function using MultiDim in order to get the correct type using type inference, then assign the passed variable to that. This works because arrays are passed by reference not value. (Why yes, that is an annoying hack. ;) Proper multi-dimensional array support in JS would be nice, eh?)

function Something (multiDimArray) {
   var realArray = new MultiDim.IntArray(0, 0); // This is just to get "realArray" to be the correct type, the dimensions don't matter and might as well be 0
   realArray = multiDimArray;
}
Comment
Add comment · 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
0

Answer by fenderrex · Jan 06, 2018 at 01:00 AM

How BCE0005: Unknown identifier: 'MultiDim' affected my workflow. so I find out you need a script for MultiDim. the script is "outdated" and in 404 land "slow clap for unity everyone". I find that apparently its because you can pass a multidimensional array of type float but not int? However, I haven't been able to pass this in a function... it's sad how they made their own javascript engine. I was trying to port over PCA to unity so I could sort items in 3D space for binary search.

  1. Sources.

  • PCA https://github.com/JosuaKrause/mdsjs

  • MultiDim https://forum.unity.com/threads/multidim-error-using-terrainimporter-js.173789/

Comment
Add comment · 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

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

1 Person is following this question.

avatar image

Related Questions

Passing Object References Through Function 0 Answers

Instantly pass other script's variable value to another. 2 Answers

c# 2D array error: need Help! 1 Answer

Projectiles passing through objects 0 Answers

Instantiate question 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