9 Replies Latest reply on Sep 14, 2007 3:45 PM by kglad

    I need help with a clear interval code

      Basically, I am creating a side-scrolling game, and I want the character to be invincible for half a second after they get hurt. I have a set interval and it works fine for the first time, but then when I hit the object again it doesn't wait a second (it immediately gets hurt when you touch the harmful object). I'm pretty sure that the interval isn't being cleared. Here is my code:

      function hitable() { //called everytime I hit something that hurts me (a spike for now)
      ableToBeHit = false; //can't be hit
      function timers() { //interval function
      clearInterval(myInterval); //clears the interval
      ableToBeHit = true; //make me be able to get hit again
      myInterval = setInterval(timers, 1000); //calls the function every 1 second

      Any help would be loved. Thanks in advanced