boardgameio / boardgame.io

State Management and Multiplayer Networking for Turn-Based Games
https://boardgame.io
MIT License
10.03k stars 709 forks source link

events.endTurn() doesn't work with multiplayer: local #388

Closed peelin closed 5 years ago

peelin commented 5 years ago

I'm trying to get Local Master multiplayer working, looking at

https://boardgame.io/#/multiplayer

In the version in the codesandbox,

This works as expected, you can play as both players by alternating between the first client and the second client.

However, if we modify the code as follows, to match with the beginning tutorial at https://boardgame.io/#/tutorial:

then the game stops working. Clicking on the first client results in error: ERROR: invalid stateID, was=[1], expected=[0] and it seems as the turn doesn't end.

Shouldn't both methods work?

Note: If we run without local multiplayer mode by using const App = Client({ game: TicTacToe, board: TicTacToeBoard, }); export default App;

Then everything works fine.

nicolodavis commented 5 years ago

Thanks for the report.

This is due to a race condition where the client is not seeing the new game state between the move and the end turn event. I'll take a closer look soon.

nicolodavis commented 5 years ago

A workaround for now (until this gets fixed) would be to wrap the endTurn in a setTimeout like this:

onClick(id) {
  this.props.move.clickCell(id);
  setTimeout(() => this.props.events.endTurn(), 0);
}
nicolodavis commented 5 years ago

Fixed in v0.31.5.

Can you upgrade and try?