Skip to main content
added 46 characters in body
Source Link

Get return of asynchronous callback insince module export nodejs- Nodejs

Server:

require('./MovimientoJugador')();
var camino4=MoverJugador(startX,startY,endX,endY,mapa2); 
console.log("Camino: " + camino4);

ClientMovimientoJugador:

module.exports = function() { 
  var Camino="uno";
 this.MoverJugador = function(startX,startY,endX,endY,mapa) {
easystar.findPath(startX, startY, endX, endY,function( path ) {
Camino=JSON.stringify(path);
 console.log("C:" + Camino)
 return Camino;
}}

Console:

Camino= uno
C=(X:1,Y1)(X2:Y2) etc...

The variable Camino has the value of one when declared. At the time that the server shows it, it does not give you time to show the last return value.

How could I turn this into a promise or make a wait of x seconds?

Get return of asynchronous callback in module export nodejs

Server:

var camino4=MoverJugador(startX,startY,endX,endY,mapa2); 
console.log("Camino: " + camino4);

Client:

module.exports = function() { 
  var Camino="uno";
 this.MoverJugador = function(startX,startY,endX,endY,mapa) {
easystar.findPath(startX, startY, endX, endY,function( path ) {
Camino=JSON.stringify(path);
 console.log("C:" + Camino)
 return Camino;
}}

Console:

Camino= uno
C=(X:1,Y1)(X2:Y2) etc...

The variable Camino has the value of one when declared. At the time that the server shows it, it does not give you time to show the last return value.

How could I turn this into a promise or make a wait of x seconds?

Get return of asynchronous callback since module export- Nodejs

Server:

require('./MovimientoJugador')();
var camino4=MoverJugador(startX,startY,endX,endY,mapa2); 
console.log("Camino: " + camino4);

MovimientoJugador:

module.exports = function() { 
  var Camino="uno";
 this.MoverJugador = function(startX,startY,endX,endY,mapa) {
easystar.findPath(startX, startY, endX, endY,function( path ) {
Camino=JSON.stringify(path);
 console.log("C:" + Camino)
 return Camino;
}}

Console:

Camino= uno
C=(X:1,Y1)(X2:Y2) etc...

The variable Camino has the value of one when declared. At the time that the server shows it, it does not give you time to show the last return value.

How could I turn this into a promise or make a wait of x seconds?

Source Link

Get return of asynchronous callback in module export nodejs

Server:

var camino4=MoverJugador(startX,startY,endX,endY,mapa2); 
console.log("Camino: " + camino4);

Client:

module.exports = function() { 
  var Camino="uno";
 this.MoverJugador = function(startX,startY,endX,endY,mapa) {
easystar.findPath(startX, startY, endX, endY,function( path ) {
Camino=JSON.stringify(path);
 console.log("C:" + Camino)
 return Camino;
}}

Console:

Camino= uno
C=(X:1,Y1)(X2:Y2) etc...

The variable Camino has the value of one when declared. At the time that the server shows it, it does not give you time to show the last return value.

How could I turn this into a promise or make a wait of x seconds?