*** need help debugging this code ***


#1

My best student came up with a game where you click on certain sprites and they disappear, adding 1 to the score at the top-left of the game screen. When the score reaches 8, the sprites change to a different animal.

The problem is that when she runs the program, the numbers in the score don’t go up by one each time she clicks on a sprite. It might be a 3, 4, 6, or whatever, even though she’s only clicked on one sprite.

Can you help debug the code–please!? It’s from Unit 3, Lesson 22:11 of Computer Discoveries.

Thanks very much!

Gary Ellis
Middle School Teacher


#2

Hi Gary,
mousePressedOver() is true any time the mouse button is being held down. I found I could actually score points my just clicking and dragging around over the various sprites. To make sure you you only get one point per click, she may want to check if the mouse just went down. Something like:
if (mouseWentDown("leftButton" && mouseIsOver(sprite))


#3

Superb, Mike! It worked. Thanks very much.

Gary