Hello,
I am trying to make a 2 dimensional array with the first dimension containing an array of floated lists. The problems happens when I try to use what is in the first dimension (as Unity recognizes it as an array of ‘Objects’ instead of an array of floated lists). Here is my code…
@HideInInspector
var pPitches : Array;
...
function Start () {
pPitches = new Array();
pPitches.Clear();
}
...
function getPitches() {
pPitches.Clear();
//Add a float list to my array.
pPitches.Add(new List.<float>());
...
//Clear the float list after adding it to the array (which is the second dimension).
pPitches[pPitches.length-1].Clear();
//Assets/scripts/record.js(148,33): BCE0019: 'Clear' is not a member of 'Object'.
//pPitches[0] should be recognized as data type 'List.<float>', not data type 'Object'.
}
Second, you are making a jagged array, not a 2d array.
Third, you are using unityscript arrays, which are untyped. You are already using a generic list for the second list/array, so why not use it also for the first dimension? like “var pPitches : List.<List.>;”
#pragma strict causes the compiler to be stricter to prevent dynamic typing. The benefit of this, is that the code will be faster, and decreased runtime errors, because the type can be checked at compile time.
Yes, don’t remove #pragma strict, and don’t use Array. Just note that there’s a bug in the Unityscript compiler that always interprets >> as the bitshift operator, so you have to write it as “var pPitches : List.<List. >;”. (Note the space.)
Thank you. What happens when I want to create a float List, and use a function later on that calls AudioClip.GetData() and can not pass the float list to AudioClip.GetData(). I know better than to try…
AudioClip.GetData(floatList.ToArray(), 0);
Does that mean I have to create a separate array and wouldn’t that effect the speed?