I’m working on the Roguelike Dungeon Crawler project, using Create-React-App. I have all of the code written and all of the packages I need installed and it should be ready to go. Yet I’m getting this error in the index.js file of my Map Generator folder, which is meant to generate the map. This is the sample of code that says is causing the issue. It specifically highlights the If statement.
I’ve edited your post for readability. When you enter a code block into the forum, remember to precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.
Right above the if statement, I would put the following console.log statement to see where the undefined values are located:
I’ve tried doing this but I still can’t find where the undefined values are. Wouldn’t all the values in the If statement already be defined by making them constants?
Uncaught TypeError: Cannot read property 'undefined' of undefined
at generateLevel (index.js:121)
at generateDungeon (index.js:132)
at new App (App.js:63)
at constructClassInstance (react-dom.development.js:9760)
at updateClassComponent (react-dom.development.js:10215)
at beginWork (react-dom.development.js:10605)
at performUnitOfWork (react-dom.development.js:12573)
at workLoop (react-dom.development.js:12682)
at HTMLUnknownElement.callCallback (react-dom.development.js:1299)
at Object.invokeGuardedCallbackDev (react-dom.development.js:1338)
at invokeGuardedCallback (react-dom.development.js:1195)
at performWork (react-dom.development.js:12800)
at scheduleUpdateImpl (react-dom.development.js:13185)
at scheduleUpdate (react-dom.development.js:13124)
at scheduleTopLevelUpdate (react-dom.development.js:13395)
at Object.updateContainer (react-dom.development.js:13425)
at react-dom.development.js:17105
at Object.unbatchedUpdates (react-dom.development.js:13256)
at renderSubtreeIntoContainer (react-dom.development.js:17104)
at Object.render (react-dom.development.js:17129)
at Object../src/index.js (index.js:6)
at __webpack_require__ (bootstrap 5c6120574084172ab8ec:669)
at fn (bootstrap 5c6120574084172ab8ec:87)
at Object.0 (index.js:7)
at __webpack_require__ (bootstrap 5c6120574084172ab8ec:669)
at bootstrap 5c6120574084172ab8ec:715
at bundle.js:719
This code above returns undefined, which causes both randomRow and randomCol to be undefined. If you are not sure why it is returning undefined, then I suggest you review arrow function syntax.