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

109
Visualizações
JavaScript asíncrono eliminar documento de base de fuego

Tengo una función que verifica si la bala golpea a un jugador, y si es así, debería eliminar la bala y el jugador que fue golpeado.

Tengo check_if_bullet_hit_player(bulletRef) que obtiene una referencia de viñeta, y la identificación del jugador recibió un disparo.

También tengo una función shoot() que llama a check_if_bullet_hit_player(bulletRef) para cada movimiento de bala.

Actualmente, cuando una bala golpea a un jugador, la bala desaparece, pero no puedo hacer que el jugador que recibió el golpe también desaparezca.

Intento - 1:

Probé la siguiente función shoot :

 function shoot(speed=0.5, distance=5, targetX, targetY){ var shoot = setInterval(function() { check_if_bullet_hit_player(bulletRef).then(player_got_shot_id => { if (player_got_shot_id != ""){ clearInterval(shoot); bulletRef.remove(); hitPlayerRef = firebase.database().ref(`players/${player_got_shot_id}`); hitPlayerRef.once("value").then(function(){ alert("hi"); hitPlayerRef.remove(); }) } }) }) }

hi una alerta cuando un jugador recibe un golpe, y el jugador que recibe el golpe desaparece por un momento y luego se vuelve a crear (que no es lo que se busca). Creo que el reproductor se vuelve a crear debido a la sincronización, así que probé diferentes métodos.

Intento - 2:

Intenté como la siguiente respuesta de desbordamiento de pila , que espera a que regrese la referencia:

 function shoot(speed=0.5, distance=5, targetX, targetY){ var shoot = setInterval(function() { check_if_bullet_hit_player(bulletRef).then(player_got_shot_id => { if (player_got_shot_id != ""){ clearInterval(shoot); bulletRef.remove(); await firebase.database().ref(`players/${player_got_shot_id}`).remove(); } }) }) }

y obtengo:

Uncaught SyntaxError: await is only valid in async functions and the top level bodies of modules

Intento - 3:

Traté de esperar con then :

 function shoot(speed=0.5, distance=5, targetX, targetY){ var shoot = setInterval(function() { check_if_bullet_hit_player(bulletRef).then(player_got_shot_id => { if (player_got_shot_id != ""){ clearInterval(shoot); bulletRef.remove(); hitPlayerRef = firebase.database().ref(`players/${player_got_shot_id}`); return hitPlayerRef.get(); // HERE we chain the promise } }).then(hola => { hola.remove(); }) }) }

Pero nada pasa.

¿Cómo puedo hacer que el jugador golpeado desaparezca?

about 4 years ago · Juan Pablo Isaza
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