Could someone please just post an example of declaring and using a multidimensional area in Unity 3.2 JavaScript. It’s not in the docs and I’ve scoured the internet to no avail. Thank you for any assistance you can provide.
It’s not any different than C#:
var foo = new int[10,20];
foo[2,5] = 42;
–Eric
Thank you very much for your quick reply. This should REALLY be in the docs.
did you expect it to be something else?
It’s in the “what’s new” (http://unity3d.com/unity/whats-new/unity-3.2) - “Multidimensional arrays: int[,]”
The annoying bit is that unityscript has always supported multidimensional arrays… it just couldn’t initialize them.
Can someone tell me how to initialize a multidimensional array in JS in one fell swoop?
public var multiDimensionalArray: int[,] = [
[0,1,1,2],
[1,0,1,2],
[1,1,0,2],
[1,1,1,0]
];
Doesn’t work, and causes and error “Cannot convert ‘int[ ][ ]’ to ‘int[,]’.”
If you leave off the type, then type inferencing will make it an int[ ][ ] (as the error implies), which is a multidimensional array, although not quite the same as int[,]. Now the next step is to get things like int[ ][ ] to be recognized explicitly as a valid type… (i.e., “var foo : int[ ][ ];” doesn’t work although it should.)
–Eric