title: JavaScript, node.js wait for socket.on response before continuing
body: <p>I need to get information from the server on the client side. 
  So on the server side I got this when a client first connect:</p>
  
  <pre><code>socket.on('adduser', function(username){
      // misc code, where i set num_player and whatnot
      socket.emit('confirmauth', socket.id, socket.num_player, function(data){
           console.log(data)
      });
      // code
  }
  </code></pre>
  
  <p>and on the client side I got this:</p>
  
  <pre><code>var current_player;
  socket.on('confirmauth', function(id, username, num, callback) {
  
      current_player = new Player(username,id, num);
  
      console.log(current_player.id); // works
      console.log(current_player.num); //works
      callback('ok i got it');
  });
  
  console.log(current_player.id); //undefined
  console.log(current_player.num); //undefined
  </code></pre>
  
  <p>my problem is that outside of the socket on, the player is not defined. It seems that javascript doesn't wait for my socket on to retrieve data before carrying on.</p>
  
  <p>I tried to wrap socket.on in a $.when done, but it doesn't work. I tried to do a callback, but I think I may not have understood very well how it is supposed to work. So if one of you is willing to help me, I will be grateful</p>
  
  <p>Thank you for your answers.</p>