I'm using the MultiDim helper script, and it's throwing a problem when I try to define a multidimensional array with sizes set by variables (not explicitly set in the editor - they will be determined by code):
* EDIT - here's a script showing just the problem * This gets rid of the whole nodes thing in the script I'd included earlier and just shows the MultiDim problem. This script sets random sizes for a 3 dimensional array, and then attempts to fill each entry in the array with the number 1. The console error shows that even accessing Index(0,0,0) proves out of range.
Here it is, all outside of any function. This produces an Array Index Out Of Range error:
var mazeWidth : int;
var mazeHeight : int;
var mazeDepth : int;
mazeWidth = Random.Range(5,10); // anything from 5 to 9
mazeHeight = Random.Range(5,10); // anything from 5 to 9
mazeDepth = Random.Range(5,10); // anything from 5 to 9
Debug.Log( mazeWidth.ToString() );
Debug.Log( mazeHeight.ToString() );
Debug.Log( mazeDepth.ToString() );
var mazeNode = MultiDim.IntArray(mazeWidth,mazeHeight,mazeDepth);
for (var a =0;a<mazeWidth;a++) {
for (var b=0;b<mazeWidth;b++) {
for (var c=0;c<mazeWidth;c++) {
Debug.Log( "Filling "+a.ToString()+","+b.ToString()+","+c.ToString() );
mazeNode[a,b,c] = 1;
}
}
}
And here it is with functional code inside the Awake function. This results in a "Field 'System.Int32[,,]' not found" error.
var mazeWidth : int;
var mazeHeight : int;
var mazeDepth : int;
var mazeNode;
function Awake() {
mazeWidth = Random.Range(5,10); // anything from 5 to 9
mazeHeight = Random.Range(5,10); // anything from 5 to 9
mazeDepth = Random.Range(5,10); // anything from 5 to 9
Debug.Log( mazeWidth.ToString() );
Debug.Log( mazeHeight.ToString() );
Debug.Log( mazeDepth.ToString() );
mazeNode = MultiDim.IntArray(mazeWidth,mazeHeight,mazeDepth);
for (var a =0;a<mazeWidth;a++) {
for (var b=0;b<mazeWidth;b++) {
for (var c=0;c<mazeWidth;c++) {
Debug.Log( "Filling "+a.ToString()+","+b.ToString()+","+c.ToString() );
mazeNode[a,b,c] = 1;
}
}
}
}