Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

So basically, I am making a robot object in javascript using Three.js and am passing in the three.js scene variable object I am using to draw the robot parts through the array- for some reason, though, the scene object will not pass into the function (it won't draw)- Am I missing something about javascript functions?

function Robot(sc){
    this.sc=sc;

    var robtexture = new THREE.MeshLambertMaterial({
        map: THREE.ImageUtils.loadTexture('tex/dmetal.png')
    });

    this.parts = [];

    var current;

    //make body

    current=new THREE.Mesh(new THREE.CubeGeometry(10,15,10), robtexture);

    this.parts.push(current);

    alert("hit");

    //make legs
}

Robot.prototype.draw = function() {
    for (x in this.parts){
        this.sc.add(x);
        alert("hit");
    }
}
share|improve this question

1 Answer 1

up vote 0 down vote accepted

Maybe this works more like you intended:

Robot.prototype.draw = function() {
  for (x in this.parts){
    this.sc.add(this.parts[x]); // < - spot the difference :)
    alert("hit");
  }
}
share|improve this answer
    
Oh ok...so I thought that the x represented the actual objects like it does in regular Java- is that not the case? –  Skorpius Jul 11 '13 at 18:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.