0

Im using three multiple arrays in a project and I have to be able to cross reference them is there anyway I can set more than one bit of data to an element in the array?

For example I have an array called ballArray[] I use it like this:

function createBall(tempPosSize)
    {
        geometry = new THREE.SphereGeometry(tempPosSize,16,16),
        new THREE.MeshLambertMaterial({color: 0xff0000,reflectivity: 0.0});
        ball = new THREE.Mesh( geometry, material );
        ballArray[i] = ball;
    }

Is there a way I can set the [I] element like you would in JSON. So I would have ballArray[i] = {Name : foobar, BallData: ball}?

1
  • 4
    Like ballArray[i] = { data: ball, name: '1' }; ? Commented Apr 9, 2015 at 13:36

1 Answer 1

1

It is possible exactly how you tried but there are some minor problems when setting the variables:

var ballArray = new Array();

function createBall(tempPosSize)
{
    var geometry = new THREE.SphereGeometry(tempPosSize,16,16),
        material = new THREE.MeshLambertMaterial({color: 0xff0000,reflectivity: 0.0});

    var ball = new THREE.Mesh( geometry, material );

    ballArray.push({Name: 'test', BallData: ball});
}
Sign up to request clarification or add additional context in comments.

1 Comment

Ya it works. Just a slow afternoon i was calling ballData instead of BallData. thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.