From ae023ff6105e0d1b3e3278b4c651dd050a144026 Mon Sep 17 00:00:00 2001 From: Elijah Cohen Date: Thu, 18 Apr 2019 10:32:55 -0500 Subject: [PATCH] communication works how I want it to! yay --- server/game.js | 5 ++--- server/player.js | 7 ++++++- web/test.js | 1 - 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/server/game.js b/server/game.js index 1ea9ede..451aca7 100644 --- a/server/game.js +++ b/server/game.js @@ -8,13 +8,12 @@ function Game(players) { } Game.prototype.start = function(ms) { - var me = this; - var tmpfn = function() {me.getNextFrame()}; + var _this = this; + var tmpfn = function() {_this.getNextFrame()}; this.timeout = setInterval(tmpfn, ms); } Game.prototype.getNextFrame = function() { - console.log(this); var inputs = this.players.map(function(p) {return p.get_status();}); this.state.update(inputs); var state = this.state.getState(); diff --git a/server/player.js b/server/player.js index 0c0767e..48f0723 100644 --- a/server/player.js +++ b/server/player.js @@ -3,9 +3,14 @@ function Player(ws) { this.status = 'x'; this.socket = ws; - this.socket.onmessage = this.listener; + var _this = this; + var fn = function(msg) { + _this.listener(msg); + } + this.socket.onmessage = fn; } +// this should probably be renamed... Player.prototype.listener = function(msg) { var data = msg.data; if(typeof data == "string" && data.length > 0) { diff --git a/web/test.js b/web/test.js index aabbe0e..311bfb4 100644 --- a/web/test.js +++ b/web/test.js @@ -6,7 +6,6 @@ theSocket = null; function send(k, s) { // sends key k thru socket s - console.log(k); theSocket.send(k); } -- 2.39.2