function Afunction(x:String,y:int){//THIS ALL WORKS WITH TheArray being directly called
var Myoutput = new String[TheArray[y].length];
Myoutput[0] = x + " " + TheArray[y][0];
for(var i : int = 1; i<(TheArray[y].length);i++){
Myoutput = SomeOtherArray[0][ConvertToSomething(x,TheArray[y])];
}
return Myoutput;
}
function AMoreDynamicfunction(x:String,y:int,ThePassedArray:Array){//This throws errors with ThePassedArray being seen as some object
var Myoutput = new String[ThePassedArray[y].length];
Myoutput[0] = x + " " + ThePassedArray[y][0];
for(var i : int = 1; i<(ThePassedArray[y].length);i++){
Myoutput = SomeOtherArray[0][ConvertToSomething(x,ThePassedArray[y])];
}
return Myoutput;
}
private var TheArray = [
[“word”,“1”,“2”,“3”,“17”,“2”],
[“words and stuff”,“1”,“2”,“3”],
[“another word”,“1”,“2”,“3”,“4”]];
The compiler error happens before I even get to set up a call to the second (more dynamic) version.
The first function runs perfectly but I wanted to create a similar function using only a different array so I thought it would be great to only need one function and make the array a passed variable so I can just send any array to the one new function. This however gives these errors:
**‘length’ is not a member of ‘Object’.
Type ‘Object’ does not support slicing.**
Is there any way to do this in UnityScript (js) or am I going to have to make the same function again with a different array directly called inside like the first one? I could probably copy the array to another array right before the function call and then directly call that changing array in one function… but isn’t that the whole point of passing an array to a function? Why is this not working?
P.S. in case people wonder TheArray[y].length is correct, It is not meant to be TheArray.length. I am specifically doing this to check the length of an array within an array which works fine in the first function. The first function is 100% working.
Can you show the code where you define "TheArray" and where you are calling "AMoreDynamicfunction"?
– bobisgod234