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
2
Question by Monko · May 15, 2013 at 10:19 PM · arraymultidimensional

I don't know how to do multidimensional arrays

For some reason, unity wont let me create an 8 dimensional array like this:

 var verlist : int[,,,,,,,] = new int[2,2,2,2,2,2,2,2];

but has no problem with a 4 dimensional array like this:

 var verlist : int[,,,] = new int[2,2,2,2];

Its the exact same code, but unity sends the error message:

No appropriate version of 'boo.Lang.Builtins.matrix' for the argument list '(int, int, int, int, int, int, int, int)' was found

Does anyone have any idea why and how to fix this?

Comment
Add comment · Show 5
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 whydoidoit · May 15, 2013 at 11:00 PM 0
Share

What on earth are you doing with an 8 dimensional array ???? :D

I'm guessing that's breaking a design limit...

avatar image SirMalarkey · May 15, 2013 at 11:38 PM 1
Share

for some reason 8 makes me think of using a look up table and binary, but you probably need more numbers than 1s and 0s so don't $$anonymous$$d me...

avatar image Monko · May 16, 2013 at 12:55 AM 0
Share

Actually, I only need 1s and 0s. Im using the 8 dimensional array in a marching cubes algorithm Im designing.

avatar image Fattie · May 16, 2013 at 08:10 AM 0
Share

@$$anonymous$$onko I would like to think I know about cubes, dimensions, and how lucky the number 8 is in Chinese culture, but it's not immediately apparent to me why one would use sparse "8 dimensional" booleans in an algorithm related to these things.

Purely as a curiosity can you explain simply in a sentence how you use it in your algorithm??

avatar image Monko · May 16, 2013 at 10:05 PM 0
Share

Ok, im using an 8 dimensional array for the marching cubes algorithm. (if you dont know what that is, look at this website http://paulbourke.net/geometry/polygonise/)

The marching cube algorithm turns "on" and "off" the vertices in a 3d grid. Each cube in the 3d grid of vertices has 8 corners (like all cubes do). Because Im generating a unique set of triangles for each possible combination of corners turned on and off in each cube, i decided to create an 8th dimensional array to handle it all. (If that makes any sense at all)

2 Replies

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

Answer by whydoidoit · May 15, 2013 at 11:42 PM

Create a flat array and make a mapping function to it:

  var eightDimensionalArray = new int[256];
  
 function GetElement(x1:int,x2:int,x3:int,x4:int,x5:int,x6:int,x7:int,x8:int):int
 {
     return eightDimensionalArray[ ((x8 << 7) + (x7 << 6) + (x6 << 5) + (x5 << 4) + (x4 << 3) + (x3 << 2) + (x2 << 1) + x1)];
 }
  
 function SetElement(x1 : int, x2 : int, x3 : int, x4 : int, x5 : int, x6 : int, x7 : int, x8 : int, value: int)
 {
      print( (x8 << 7) + (x7 << 6) + (x6 << 5) + (x5 << 4) + (x4 << 3) + (x3 << 2) + (x2 << 1) + x1);
      eightDimensionalArray[ ((x8 << 7) + (x7 << 6) + (x6 << 5) + (x5 << 4) + (x4 << 3) + (x3 << 2) + (x2 << 1) + x1)] = value;
 }
  
 SetElement(0,0,0,1,0,0,0,1,5); //example to "Set" a value in the array
 print(GetElement(0,0,0,1,0,0,0,1)); //example to retrieve whatever you set. In this case, 5.
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 SirMalarkey · May 15, 2013 at 11:44 PM 0
Share

Smart man...

avatar image Monko · May 16, 2013 at 12:53 AM 0
Share

Wow! Thanks whydoidoit! That was very clever. This works perfectly for my game.

I do have to mention, I had to edit your code a little, so I posted the working version below:

 var eightDimensionalArray = new int[256];
 
 function GetElement(x1:int,x2:int,x3:int,x4:int,x5:int,x6:int,x7:int,x8:int):int
 {
 return eightDimensionalArray[ ((x8 << 7) + (x7 << 6) + (x6 << 5) + (x5 << 4) + (x4 << 3) + (x3 << 2) + (x2 << 1) + x1)];
 }
  
 function SetElement(x1 : int, x2 : int, x3 : int, x4 : int, x5 : int, x6 : int, x7 : int, x8 : int, value: int)
 {
 print( (x8 << 7) + (x7 << 6) + (x6 << 5) + (x5 << 4) + (x4 << 3) + (x3 << 2) + (x2 << 1) + x1);
 eightDimensionalArray[ ((x8 << 7) + (x7 << 6) + (x6 << 5) + (x5 << 4) + (x4 << 3) + (x3 << 2) + (x2 << 1) + x1)] = value;
 }

 SetElement(0,0,0,1,0,0,0,1,5); //example to "Set" a value in the array
 print(GetElement(0,0,0,1,0,0,0,1)); //example to retrieve whatever you set. In this case, 5.
avatar image whydoidoit · May 16, 2013 at 07:22 AM 1
Share

Ah yep, brackets, scripting in the answer box again :S

avatar image whydoidoit · May 16, 2013 at 07:24 AM 1
Share

Updated my answer with your redone code.

avatar image
0

Answer by amostajo · May 15, 2013 at 11:34 PM

Try using something different than arrays maybe?

http://wiki.unity3d.com/index.php?title=Which_Kind_Of_Array_Or_Collection_Should_I_Use%3F

Perhaps a list will do for you.

You could create a class with the values you want, in this case since you are needing 2 ints, something like this will do:

 class MyObject {
 
   public var myIntA : int;
   public var myIntB : int;
 
   /**
     Default constructor.
   */
   public function MyObject () {
     myIntA = myIntB = 0;
   }
 
 }

You then define your list as:

 // Add this on top your script
 import System.Collections.Generic;
 
 // Here you create a list of your object, it supports more tham 8 I assure you
 var verlist : List.<MyObject>;
 
 function sampleUsage () {
   verlist = new List.<MyObject>();
 
   // Adding new object with default constructor.
   verlist.Add(new MyObject());
 
   // Adding new object with custom int values
   var newitem : MyObject = new MyObject();
   var newitem.myIntA = 5;
   var newitem.myIntB = 10;
   verlist.Add(newitem);
 
   // foreach
   foreach (var myobject : MyObject in verlist) {
     // Displaying all values in console
     Debug.Log(myobject.myIntA);
   }
 
   // Displaying value of MyObject added
   Debug.Log(verlist[1].myIntB);
 }
 
 

  
Comment
Add comment · Show 2 · 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 whydoidoit · May 15, 2013 at 11:36 PM 1
Share

The only problem with that is that it's a list of x things, that's not an 8 dimensional structure if you add 8 things to the list.

avatar image Fattie · May 16, 2013 at 06:57 AM 0
Share

"The only problem with that" awesome understatement :)

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

17 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

Related Questions

Multidimensional arrays - editing one element within one of the arrays 1 Answer

passing multi-dimensional arrays from one script to another? 1 Answer

Multidimensional array variable size (JS) 1 Answer

Javascript Endless 3D Array 0 Answers

Access a multidimensional array inside an array 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