getting an error, Uncaught TypeError: Cannot set property ‘undefined’ of undefined
the error comes in this method:
drawItems = (arr, items) =>{
items.forEach((item)=>{
console.log("creating item")
console.log(item)
let x = item[0]
let y = item[1]
arr[x][y] = 1
console.log(arr[x][y])
})
}
Which is identical to the method that preceeds it as far as I can tell in terms of it’s syntax, values passed in, etc. The error is in this line specifically:
arr[x][y] = 1
But when I log arr or log arr[anyInteger][anyInteger] (eg arr[9][23]) I get a value from the array.
The method just prior to this one, drawRooms, operates the same and has no errors.
If i comment out this routine call in the constructer, it runs fine.
In the constructor, you set rooms as an empty array, then you call generateRooms passing rooms as a parameter.
Inside generateRooms you do a forEach over rooms (which is still an empty array).
When I tried replicating your code, this is what I have found…
…After some playing about in Codepen, I made the rooms and items global vars and modified the generateRooms function. Plus I moved some calls to componentWillMount to see if that made any difference…
I looked at your changes and implemented some of them. yours seems to work well although I did not add my CSS rules to your code, but I can see the output in the console seems to be working. Thanks for takign the time to play with it. I need to look over your generateRooms more closely to see what else I can update.
The code I pushed ended up being stuck between two versions of what I was tryign and I think i let my IDE make some changes too. I cleaned up a lot of the errors you mention here. Still not working for me though.
Like I repiled to JOhnny his seems ot do what I tried to so I’ll take a better look at his code.