Line 44 error when trying to restart game

Several students are trying to add code at the end of their game to hit a button to restart. I don’t know how to code this so I don’t know how to help them.

Could you provide links to the students’ games?

Hi @sphillip,

I agree with the students - restarting your game is essential :blush:! It does; however, require some thought. Restarting the game essentially means adding code to put everything back where it started. So, if you have an “End Game” screen showing at the end, that will need to be hidden and all the beginning sprites put back in their positions. I do have a game example that restarts when the space bar is hit. If you view the code, the game restarts from the “End Screen” after you click the space bar. The code for the restart starts on line 266. When you get to functions, the blocks of code for needed to restart the game are a great use of a function.

Hope that helps!

well you have to reset properties and positions so that the game will function properly again after digging through it this should be a good start off

// replace function f with this
function restart() {
  if (keyWentDown("r") && !car.visible) {
    l1.y = randomNumber(-200, -220);
    l2.y = randomNumber(-380, -430);
    splosion1.visible = false;
    car.visible = true;

and if your student wants to add more stuff it’ll require updating this
also the error you were getting is referred to calling a function too much so it’s best to keep in mind that calling draw() usually isn’t the best idea since it’s already being called quite frequently