Skip to content

Commit 16919b7

Browse files
quit trying to store a nested array
1 parent f19238a commit 16919b7

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

otrio.html

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@
427427

428428
function sendData() {
429429
let data = {
430-
gameState: gameState,
430+
gameState: JSON.stringify(gameState), // nested arrays aren't allowed to be stored
431431
currentPlayer: currentPlayer,
432432
messages: messages,
433433
lastUpdated: new Date().getTime()
@@ -475,16 +475,21 @@
475475
messages = providedMsgs;
476476
}
477477

478+
function alignWithServer() {
479+
M.server.recall("./").then(function (data) {
480+
updateGame(JSON.parse(data.gameState));
481+
currentPlayer = data.currentPlayer;
482+
showWhoseTurn(false);
483+
updateMessages(data.messages);
484+
}).catch(function (error) {
485+
console.error("There was an error syncing the game state.");
486+
console.error(error);
487+
});
488+
}
489+
478490
function monitorStatus() {
479491
if (hasGameCode("otrio")) {
480-
serverChecker = setInterval(function () {
481-
M.server.recall("./").then(function (data) {
482-
updateGame(data.gameState);
483-
currentPlayer = data.currentPlayer;
484-
showWhoseTurn(false);
485-
updateMessages(data.messages);
486-
});
487-
}, 3000); // rechecks every 3 seconds
492+
serverChecker = setInterval(alignWithServer, 3000); // rechecks every 3 seconds
488493
}
489494
}
490495

@@ -495,10 +500,7 @@
495500
monitorStatus();
496501
} else if (status == "joined") { // if using a preexisting game code
497502
resetBoard();
498-
updateGame(data.gameState);
499-
currentPlayer = data.currentPlayer;
500-
showWhoseTurn(false);
501-
updateMessages(data.messages);
503+
alignWithServer();
502504
monitorStatus();
503505
} else if (status == "left") { // if the player left the specified game
504506
if (serverChecker) {

0 commit comments

Comments
 (0)