2D Array of GameObjects in Javascript Slicing/Typing Error

Hi guys, I’ve been having a headache with the javascript’s 2D arrays, especially with regards to typing. Here is the code:

static var NUM_COLUMNS = 3;
static var NUM_ROWS = 5;

var field : GameObject = new GameObject[NUM_ROWS][NUM_COLUMNS];
var test : GameObject;

function Start () {
	for(var child: GameObject in gameObject) {
		//		child.GetComponent(FieldSquare).getCol()] = child;
		test = child;

Clearly, test is of type GameObject and this does NOT produce an error. However, if I comment that out and use the line before it which tries to initialise the 2D array of GameObjects field, I get an “GameObject does not support slicing” error. From what I gather, for some reason, field is not being treated as a GameObject even though that’s how I’ve declared it. I’m guessing this is some quirk with javascript’s multidimensional arrays but I’ve got no idea how to work around this. Any help is much appreciated.

That’s a jagged array, not a 2D array. Also your declared type (GameObject) does not match the type of the value (GameObject). Finally, don’t run code outside of functions; only declare variables there. The syntax for 2D arrays:

var field : GameObject[,];

Then initialize it in Start, not outside:

field = new GameObject[rows, columns];