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]]
  }
}
ggorlen
  • 44,755
  • 7
  • 76
  • 106
  • 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](https://stackoverflow.com/questions/57477062/find-array-index-on-a-1d-array-from-a-2d-grid-javascript), [2](https://stackoverflow.com/questions/2151084/map-a-2d-array-onto-a-1d-array), [3](https://stackoverflow.com/questions/1730961) – ggorlen Sep 01 '22 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. – forbiddennewt Sep 02 '22 at 02:32

0 Answers0