Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

248
Vistas
clearInterval() doesn’t work properly. Intervals stack on eachother

Hello everyone I have been having trouble with the setInterval() and clearInterval() functions.

I can’t seem to figure out why it’s not working, been searching for hours trying multiple solutions

I want the user to be able to click on a zone, afterwards it spawns an enemy, you kill the enemy, another respawns

I have it like this but the problem I am having is that when the enemy refreshes, it’s health immediately drops to 0 and its almost like the setIntervals are stacking on top of each other because after it respawns it starts taking double damage.

If anyone could give me insight on this that would be great!

function selectelwynnforestzone(){
var refreshtankattackinterval = setInterval(tankattackenemy, tankattackspeed);

Codepen link https://codepen.io/jonloft/pen/eYMmYQj

(It may look a little wonky but just click the Elwynn forest button)

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

function selectelwynnforestzone(){
  var refreshtankattackinterval = setInterval(tankattackenemy, tankattackspeed);
  ^^^
  //...
}

Because that statement begins with the var keyword, the interval id is being assigned to a new variable within the scope of that function. The function that is supposed to clear the interval can only see the variable named refreshtankattackinterval that you have in the global scope. Remove that var keyword and you will assign to the global variable and it should work as you intended.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda