0

Here is my code

var chars = new function() {
  this.array = new Array(0);
  this.add = function(x, y, speed, size, color, ai) {
    this.array[array.length] = {x: x, y: y, size: size, color: color, ai: ai};
  }
}

On line 35, the only line in the function add I am getting the error "array is not defined" why is this happening and yes I did try,

chars.array[array.length] = {x: x, y: y, size: size, color: color, ai: ai};
1
  • Sorry, I can't get the code formatting to work. Commented Dec 21, 2013 at 7:44

2 Answers 2

2

you have to fix it to:

var chars = new function() {
    this.array = new Array(0);
    this.add = function(x, y, speed, size, color, ai) {
        this.array[this.array.length] = {x: x, y: y, size: size, color: color, ai: ai};
    }
}

I have changed this.array[array.length] to this.array[this.array.length]

Sign up to request clarification or add additional context in comments.

Comments

1

I would suggest you to use push method. The push method appends values to an array.

 this.array.push({x: x, y: y, size: size, color: color, ai: ai});

Comments

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.