io.sockets.on('connection', function (socket) { socket.on('requestGame', function (data) { for (var game in games) if (game.player2 === undefined) { game.player2 = socket; socket.emit('gameStart', { game_id: game.game_id, turn: !p1_turn }); // works game.player2.emit('gameStart', { game_id: game.game_id, turn: !p1_turn }); // doesn't work Why does one of these lines work while the other doesn't?
here is the error
game.player2.emit('gameStart', { game_id: game.game_id, turn: !game.p1_tur ^ TypeError: Cannot call method 'emit' of undefined