Closed Stefan-Hanke closed 4 years ago
Should we just consider this user error, i.e. if you use movesPerTurn
, your game logic is flawed if you also call endTurn
from your move?
What about:
move: moveName(G, ctx) {
ctx.events.endTurn();
ctx.events.endTurn();
}
This will also result in multiple endTurn
calls being emitted. Should we try to second guess this as well?
The reasons I'm OK with writing this off as user error without writing more code to handle it:
move: moveName(G, ctx) {
ctx.events.endTurn();
ctx.events.endTurn();
},
flow: {
onTurnEnd(G) {
console.log('turn end');
return G;
}
}
endTurn
affecting another player's turn. Reference: https://github.com/google/boardgame.io/commit/c4a11a79292700cf9d6afde737cabd0089941b8dSounds reasonable.
I don't know whether this is documented, but there should be a paragraph about using movesPerTurn
in a flow.
What I'm unhappy with is that such errors behaviours get silently ignored (e.g. it's not allowed to call that event? The framework will just ignore it...). The game should work given all those checks but I'd like it to be a bit more perceptible.
Makes sense. I definitely think we should do more error logging (perhaps using a custom log function that is automatically stripped out in production builds). That way we can alert the developer to mistakes like this (and other things like forgetting to return G from a move).
I'll add an issue for this: #253
This is a follow-up issue from #241.
When a flow uses the
movesPerTurn
property (e.g. in the TicTacToe example), the library will call events automatically, even when a move also called into events.Events should be called exactly once as they happen, regardless of whether a game calls into events or not.