1

I attempted to make a basic game where you should click the Dragon and not the girl. I wanted to make it so that when you click the girl you lose a health point and when your health point reaches 0 you go to a screen that says "Game over". My problem is making Scratch notice that the Lifes variables has reached zero. I used the if function and the equality operator and I failed to make it work.

Here is the link to my project: http://scratch.mit.edu/projects/41738808/

  • Welcome to the CS50 StackExchange community! Please notice your question is a little broad (as in "please review my code"). You got lucky this time ;) but for your next questions try following premises here. That way you may improve your chances of getting answers to your questions. – abelinux Jan 5 '15 at 4:03
2

The problem is that the condition Lifes = 0 is only checked once, when the game starts. At that point in the game Lifes = 3, always, so the first condition is ignored because it is false, and the else statement is triggered, which leads to an infinite loop for the rest of the game.

In order to fix your script, you must check if Lifes = 0 throughout the game, not just at the start of it.

| improve this answer | |
  • 1
    That was it! Thank you very much that was very helpful! – Saito Jan 5 '15 at 3:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .