0

I have a 2D array that is full of literal objects. The objects have properties that are either true or false. My problem:

I have tried setting the the properties in this fashion

SpacesObjectsArray[2][0].HasRotator = true;

This however, will set every .HasRotator property in the array to true not just the one located at [2][0].

What am I doing wrong?

3
  • 1
    How are you constructing the array? Could you post a code snippet, please? Commented Aug 27, 2011 at 0:05
  • 3
    Seems to me that every element of the array references the same object. How are you creating the array? Commented Aug 27, 2011 at 0:06
  • "References the same object" This sounds like what I'm doing wrong. I'm going to mess with this and get back to ya. Thank ya! Commented Aug 27, 2011 at 0:10

1 Answer 1

1

I coded it up just to show you that it works if you create your arrays properly: http://jsfiddle.net/jfriend00/3uxcr/. Therfore, there must be a problem with the way you are creating the two dimensional array because if it is created properly, the line of code you have works.

As others have said, you may have an array of references to all the same object and thus when you change that object, all the references see the change to the same object.

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

1 Comment

Yup thats what I was doing. I was just sticking the same object in the array over and over. Thanks alot jfriend00 and Felix Kling

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.