Updating an array indices dynamically

All,

I have a script that records the time and 3D transform positions since game load. I want to end up with an array like this, which records all of the positions and timestamps collected for the positions until it reaches a certain position:

myArray =[
{positionX : #, positionY: # , positionZ : #, timeStamp: #},
{positionX : #, positionY: # , positionZ : #, timeStamp: #},
etc...];

Here is what I’ve done to take a stab at this, shortened for easier read:

var myObject : GameObject;
var myArray = new Array ();
var seconds;

function Update(){
	
//stuff here to find seconds, deleted to save space
	
for (var i=1;i<transformarray.length;i++){
    myArray*={};*

_ myArray*.positions=myObject.transform.localPosition; //here, positionX, etc*_
_ myArray*.timeStamp =seconds;
};*_

*if (myObject.transform.localPosition.x = 1 &&myObject.transform.localPosition.z = 3 &&myObject.transform.localPosition.y = 2) { *
stop updating array
Debug.Log(myArray);
}
}
Instead, I get
Debug.Log[Object[]);
Could someone help me with this?

Try using == instead of =

if (myObject.transform.localPosition.x = 1

if (myObject.transform.localPosition.x == 1

Also, try looking at an array element or value instead:

Change:

Debug.Log(myArray);

To:

Debug.Log(myArray[0]);

Debug.Log(myArray[0].timestamp);

I’d rather do an array of specialized objects instead of an arbitrary array of arrays:

public class PositionWithTimestamp {
    public Vector3 position;
    public int timestamp
    public PositionWithTimestamp (Vector3 position, int timestamp) {
        this.position = position;
        this.timestamp = timestamp;
    }
}

then you can fill it dynamically like this:

List<PositionWithTimestamp> positions = new List<PositionsWithTimestamp>();

if(transform.position.x != 1 && transform.position.y != 2 && transform.position.z != 3) { // choose your values as you need
    positions.Add(new PositionsWithTimestamp(transform.position, seconds));
}

This way you will be adding your positions as long as you don’t stand in that specific position. To stop all adding you could do the following:

bool addPositions = true;

if(transform.position.x != 1 && transform.position.y != 2 && transform.position.z != 3) { // choose your values as you need
        addPositions = false;
    }

if(addPositions){
    positions.Add(new PositionWithTimestamp(transform.position, seconds));
}

All assuming that you’re doing it in Update()

Also I’d recommend to switch to C# since UnityScript is deprecated and this will bite you in the a$$ later.