+ 1
Help Please! I can’t make my code work.
Whenever I tap on the canvas to put down an x it says “TypeError: undefined is not an object (evaluating 'this.board[x][y]')” and as far as I can tell “board[x]” appears not to be returning an array so I can’t put the “[y]” at the end of it, but “board” should always be a 2d array and nowhere does it directly assign a value to “board[x]”. It only ever assigns a value to “board[x][y]” and when assigning to “board” directly it only ever assigns it a 2d array. https://code.sololearn.com/WsF813udH47Y/?ref=app
11 ответов
+ 3
Hi! I see your code, and you probably tried lots of things to fix it, but here's the most important thing of all:
Checking.
Every.
Value.
In the function, the arguments passed (x, y) are ALWAYS 3; and try getting that index with an array of 3 elements. I didn't look at your code to get the sourve of the error, you are probably more suited for that job
+ 3
Jason Stone It's up to you to remove or keep this. However, I would consider keeping it as it could show others how you were able to resolve your own code issue. I also think it's great how other well known canvas guys contributed.
This question certainly meets the criteria for Q&A 😉
+ 2
I did try commenting out some code which just shifted the error from “board.makePlayerMove()” to “board.winner()” where it said “TypeError: undefined is not an object (evaluting ‘this.board[0][0]’)” so somehow “board” is losing the 2d-ness of its array. I also tried changing the code in “board.winner” so it checked “this.board[1][0]” first but same problem. “this.board[1]” didnkt return an object.
+ 2
I’ll try to look at it when I have a little time, but if you’d like you can check out mine, it may give you an idea or two.
https://code.sololearn.com/WGw5U9qtrrM2/?ref=app
I believe there are a few others out there as well
+ 2
I found the problem. I kept using the format “for (myvar = 0; myvar < mylimit; myvar++)” instead of “for (let myvar = 0; myvar < mylimit; myvar++)”. This caused all kinds of issues as it looked for any reference to “myvar”, even from different sections of the code, and used that causing things to go haywire.
Now that I found the problem, I edited the tags to include “mfd” which marks this question to be automatically deleted 24 hrs after the tag was added.
+ 2
Jason Stone Looks like your question remained after you removed your self applied mfd tag. 👌
+ 1
wow, 309 lines! Impressive. Mine is half that.
+ 1
once mfd is added, even if its removed it still automatically deletes the thread right?
+ 1
I read that someone asked about what mfd means and tagged their post with mfd and it was deleted. Anyway, I’ll remove the mfd and see what happens.
+ 1
Jason Stone
It shouldn't. I've removed an mfd added by another Gold Mod and the post remained. It might be different if someone removes an mfd added by a mod.
Or... that could result in an account being deactivated. 😮
That said, I never considered if mfd worked when someone applied it to their own post.
Have you tested this before?
I guess we'll find out in 12 hours. 🤷♂️
+ 1
David Carroll yes, it would seem so.