I have an API like this:
function movePlayer(x, y){
if (x < 0 || y < 0) return true;
else return false;
}
and now I want to change only this function so that the if-else is on the server side like this:
Client side:
function movePlayer(x, y){
var result;
socket.emit('move_player', {
_x: x,
_y: y
});
socket.on('move_finished', function(data){
result = data._result;
});
return result;
}
Server side:
var result;
socket.on('move_player', function(data){
if (data._x < 0 || data._y < 0) result = false;
else result = true;
socket.emit('move_finished', {_result: result});
});
But it won't work since the server's response is asynchronous and the client side won't wait to get the response. So is there any way of doing it by just change the function definition only?
via T. Yu
No comments:
Post a Comment