Hello,
I’ve made a javascript class named tabXY with two variable inside (x and y).
I want to make an array of these objects. But I have some problem with it.
If i do this :
var testList = new tabXY[100];
var testObject = tabXY();
testList.Add(testObject);
testList[0].x=125;
It return : ‘Add’ is not a member of ‘tabXY’.
And if I do this :
var testList = new Array();
var testObject = tabXY();
testList.Add(testObject);
testList[0].x=125;
It return : ‘x’ is not a member of ‘Object’.
Any idea?
You make the first case work by using bracket notation. Built-in .net arrays don’t have Add(). You make the second case work by casting the object back to tabXY. I’m not very firm on Java/UnityScript, though - there’s probably a better way to deal with the type mismatch you’re encountering.
#pragma strict
#pragma downcast
function Start ()
{
var testArray = new tabXY[10];
var testObject = new tabXY();
testArray[0] = testObject;
testArray[0].x = 100;
var testArray2 = new Array();
testArray2.Add(testObject);
var obj : tabXY = testArray2[0];
obj.x = 100;
}