Scoring system in a game

Hi there
I’m now creating a scoring system for my game. So when the player destroys an enemy, the score will hop up. There’s a big problem.

In my game, every enemy building and unit has a health value. When the value drops below 0, it is dead.


onClipEvent (load) {
  var health = 100
}
onClipEvent (enterFrame) {
  if (health <= 0) {
    health = 0
    _root.score += 200
  }
}

So if I code it like this, the score will soar up continuously by 200 at a time. Then I thought of defining a boolean like this:


onClipEvent (load) {
  var health = 100
  var scored = false
}
onClipEvent (enterFrame) {
  if (health <= 0) {
//the health value must be set back to zero otherwise the health bar will grow towards the negative side
    scored = true
    health = 0
    _root.score += 200
  }
  if ((scored == true) and (health <= 0)) {
//so if the player shoots the building again, the score won't grow anymore.
    _root.score += 0
  }
}

However, it did not work. How am I supposed to write this part of the script?

Thanks a lot.