# 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?

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.
``````

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.

// Adding new object with custom int values
var newitem : MyObject = new MyObject();
var newitem.myIntA = 5;
var newitem.myIntB = 10;