0

I'm unable to call a boolean and make it perform its required function for 2D arrays. Upon calling true ideally there is an image that would be found. The length of the findme variable should match the length of isFound. I am not sure how to do that. The findme variable should change the value of talent.isFound but I'm unable to change its value. Below is what I've tried.

var talent[
  [{
      PosX: 300,
      PosY: 600,
      isFound: false
    } {
      PosX: 500,
      PosY: 800,
      isFound: false
    } {
      PosX: 200,
      PosY: 600,
      isFound: false
    }
  ]
  [{
    PosX: 100,
    PosY: 200,
    isFound: false
  } {
    PosX: 300,
    PosY: 400,
    isFound: false
  } {
    PosX: 100,
    PosY: 700,
    isFound: false
  }]
]

var findme = [true, false, true, false, false, true]

for (var i = 0; i < talent.length; i++) {
  for (var j = 0; j < talent[i].length; j++) {
    talent[i][j].isFound = findme[[i][j]]
  }
}
2
  • It's hard to tell what you're asking. Can you clarify the goal? I don't see that p5.js is really relevant here, seems like a plain JS/array problem. It's a good idea to use valid JS syntax as much as possible so others don't have to guess where the problem is. findme is a 1-d array so just use one index into it: findme[i*talent[i].length+j] maybe? See 1, 2, 3 Commented Sep 1, 2022 at 14:41
  • 1
    sorry for the poor wording, what I meant is I wanted to change the talent.isFound property to true or false depending on whatever is in the findme array. So for example if it is true in the original talent.isFound property it would be changed to false in the findme property. However, the solution you provided worked! Thank you. Commented Sep 2, 2022 at 2:32

0

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.