[EXCEPTION] Painter tried to move off the grid or into an obstacle

[Posts in the debugging category need to have the following pieces of information included in order to help other teachers or our moderator team best help you. Feel free to delete everything in brackets before posting your request for debugging help.]

Link to the project or level:[ (Code.org)
What I expect to happen: [ A student is trying to create a basic checkerboard pattern. However they keep getting the following exception in the error message [EXCEPTION] Painter tried to move off the grid or into an obstacle.

What actually happens: [error message [EXCEPTION] Painter tried to move off the grid or into an obstacle. and painter stops moving at the right side of row1 ]
What I’ve tried: tried to debug it myself.

Basically, I need help with making the painter turn at the end of row 1 and continue with the checkerboard pattern

Hi, thanks for reaching out on the forum, I’m sorry you are having issues with the PatternPainter. This was a tricky lesson for me and my students when we did it recently!
The link you shared just takes me to my version of this lesson-- this happens if you copy the url from the address bar. To be able to share a link that shows your work on the level, click on the “Share” button in the blue section on the page, and then

I can’t see your specific code, but one thing to try is to use a call to the canMove() method to check if the painter can move or if they will fall off the edge. Something like:
if (canMove()){
//code to do
}else{
//code for if they are at the end of the row
}

OR, I had some students solve this using while loops,
while(canMove()){
//code to repeat until the painter gets to the edge
}
If you still have issues, please try sharing the link to your work as described above, or a screenshot of the method.
Best,
Lindsay

1 Like