- Home /
Type function(): Object[] does not support Slicing
I am loading text into an array from a text file. I know the array is being populated from when I debug the program, but when i attempt to output the information i get the error "Type function(): Object[] does not support Slicing." How do i go about fixing this? I will post my code below
var returnChar = "\n"[0];
var commaChar = ","[0];
var dataLines = dataFile.text.Split(returnChar);
var buildDataPairs = new ArrayList();
for (var dataLine in dataLines) {
var dataPair = dataLine.Split(commaChar);
buildDataPairs.Add(dataPair);
}
var dataPairs = buildDataPairs.ToArray;
Debug.Log(dataPairs[0][0]);
Not that it's related, but why use a string if you just need a char?
why var commaChar = ","[0];
and not var comma = ',';
?
That's how UnityScript does it, apparently. At least, according to the Unify Wiki
In Unityscript, both ' and " are used for strings. (One of those cases where Unityscript actually is like Javascript.) You need to reference chars by their index in a string. C# can also use that technique.
Answer by Eric5h5 · Sep 29, 2013 at 04:56 PM
Don't use ArrayList, it's slow, untyped, and obsolete. (Don't use the JS Array class either for the same reason.) Use generic Lists. Since buildDataPairs has no type, turning it into an array makes in an Object[] array, which you would need to cast in order to use.
Also you need to use ToArray() as a function, not ToArray. However, since you should make buildDataPairs into a List of String[], there's no real reason to turn it into an array, so you can just leave it as List.< String[] > and not bother with ToArray().