Help with Code for a Student

Hi to all - I have a student who is trying to have the above-linked project accomplish the following:

  • Have trees/bush/dividers/gas/pothole/coin reset once they hit their certain negative number and appear again starting from the right at their certain appearance number.
  • Have “bus” respond to up and down arrows to navigate the bus up and down on the road to avoid obstacles and collect helpful objects.
    Right now, the code is running but they do not reset and the bus is not responding to up and down arrows.
    He has tried:
  • Separating the functions for each sprite.
  • Separating the visibility calls.
  • Rearranging the commands once the sprites appear after the left click is pressed during the start-up or game over screens, at least to an extent.
  • Rearranging the functions, to an extent.
    Thank you all for your help with this!


Your student has done an amazing job with this game. One of the best I’ve seen in some time!

There is one small fault in the logic that is causing all of the problems you mention to happen.

The spriteSet function that calls all of the other functions is the issue. It is only called one time (when you click the mouse to start the game). As a result, all of the other functions only run once. I moved that block, the spriteSet block, below the if block and all of the problems you mention go away. This is not the end all solution, however, because now the game starts right away and you still have to click on the road somewhere to remove the startUp sprite and really start playing the game.

Based on your student’s ability to put this together, I’m sure they can find a solution (some kind of variable switch) that can be triggered by the mouse click and still allow the spriteSet block to be called repeatedly.

Have a good (hopefully short) week!


1 Like

Thank you so much, Mike! I will give him this feedback - it is so appreciated! ~Sheri

1 Like