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

101
Vistas
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 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