Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

306
Visualizações
I cant stop my interval and neither clearInterval() work;

I've made simple userscript for the game https://zty.pe/, The bot work on my modified version of the game, I'm trying to make it whenever I click "F" it starts running , but stops when I click " C ", the loop works normally after clicking C and it doesnt stop.

document.addEventListener('keydown', (e) => {
  key = e.keyCode
  if(key == 70){
  var zTypeBotAlphaChars = "abcdefghijklmnopqrstuvwxyz";
  var zTypeBotCharToType = 0;
  ztypebot = setInterval(function() {
  ig.game.shoot(
  zTypeBotAlphaChars.charAt(zTypeBotCharToType));
  }
  , 10);
  }
})


document.addEventListener('keydown', (e) => {
  if(e.keyCode == 67){
    clearInterval(ztypebot, 10);
  }
})
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Try adding window. before ztypebot interval to make it a global function:

document.addEventListener('keydown', (e) => {
  key = e.keyCode
  if(key == 70){
  var zTypeBotAlphaChars = "abcdefghijklmnopqrstuvwxyz";
  var zTypeBotCharToType = 0;
  window.ztypebot = setInterval(function() {
  ig.game.shoot(
  zTypeBotAlphaChars.charAt(zTypeBotCharToType));
  }
  , 10);
  }
})


document.addEventListener('keydown', (e) => {
  if(e.keyCode == 67){
    clearInterval(window.ztypebot, 10);
  }
})
about 4 years ago · Juan Pablo Isaza Relatório

0

Your ztypebot variable is local in each function, you need to define it outside like so:

let ztypebot;

document.addEventListener('keydown', (e) => {
  ...
  ztypebot = setInterval(function() {
    ...
  }
})


document.addEventListener('keydown', (e) => {
  if(e.keyCode == 67){
    clearInterval(ztypebot, 10);
  }
})
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda