From 7f109c05c5dc415b79ede9a15d15971acadf5d0e Mon Sep 17 00:00:00 2001 From: "Glitch (hello-express)" Date: Tue, 17 Mar 2020 14:51:37 +0000 Subject: [PATCH] =?UTF-8?q?=E2=98=84=EF=B8=8F=F0=9F=90=84=20Checkpoint=20.?= =?UTF-8?q?/stats.json:9949330/38=20./server.js:9949330/617?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.js | 12 ++++++------ stats.json | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 stats.json diff --git a/server.js b/server.js index deb5d73..d2894e4 100644 --- a/server.js +++ b/server.js @@ -73,10 +73,9 @@ client.on("a", (msg) => { var pos = {x: (Math.random() * 100) - 50, y: (Math.random() * 100) - 50}; var vel = {x: 2/5, y: 2/7}; -var stats = { - cornerhits: 0, - edgehits: 0 -} +var statsraw = fs.readFileSync('stats.json'); +var stats = JSON.parse(statsraw); +console.log(stats); var cursor = setInterval(function() { client.sendArray([{m:'m', x: client.getOwnParticipant().x = pos.x + 50, y: client.getOwnParticipant().y = pos.y + 50}]); @@ -110,12 +109,13 @@ var cursorupdate = setInterval(function() { } else if ((pos.x >= 50) || (pos.y >= 50) || (pos.y <= -50) || (pos.x <= -50)) { stats.edgehits += 1; } - break; - fs.writeFile("stats.json", JSON.stringify(stats), { + let statsjson = JSON.stringify(stats); + fs.writeFile("stats.json", statsjson, 'utf8', function (err) { if (err) { console.log("stats.json couldn't be saved!"); return console.log(err); } }); + break; } }, 25); diff --git a/stats.json b/stats.json new file mode 100644 index 0000000..96dc59a --- /dev/null +++ b/stats.json @@ -0,0 +1 @@ +{"edgehits":105,"cornerhits":0} \ No newline at end of file