Moves are called twice when using `multiplayer: Local()`
holgersindbaek opened this issue · 5 comments
I'm playing around with the framework by doing an implementation of 2048.
Everything worked great until I added multiplayer: Local(). If multiplayer is set to that, then all moves are called twice for some reason, which is a problem for games like 2048 where a random tile is randomly added on a move.
I'm not sure if this is a feature or a bug?
I've tweaked the tictactoe-example with a console.log in the clicCell move function. You can see in the example that it's being called twice: https://codesandbox.io/s/boardgame-io-forked-sbedgl?file=/src/game.js.
I believe this is part of an optimistic update made by the client. You can disable moves from being made on the client:
https://boardgame.io/documentation/#/secret-state?id=disabling-moves-that-manipulate-secret-state-on-the-client
That seemed to do the trick. Thanks.
If anyone wants to try out the finished version made with boardgame.io, you can check it out here: https://2048-online.io/.
Plays great @holgersindbaek! Feel free to add it to our list of games built with boardgame.io https://boardgame.io/documentation/#/notable_projects
I'm happy you like it @delucis 🙂. Thanks for the suggestion. I've created a pull request here: #1118.
I really liked my experience with boardgame.io. I might even remake my solitaire games (https://online-solitaire.com/) with it at some point.