How to dispatch move from another move automatically?
ilivss opened this issue · 1 comments
Hi,
I'm trying to invoke a move automatically from another move. For example I have the following moves:
const rollDie: Move<IState> = (G, ctx) => {
...
if(die === 5) {
// INVOKE SPAWN
}
}
const spawn: Move<IState> = (G, ctx) => {}however I can find any documentation on this nor any function that I could use to dispatch a move object.
@ilivss do you really need to invoke another move or is it rather the code path of a move. Semantically a move is something a player does actively so it doesn't really make sense to playback a move programatically in most cases.
However the type Move designates just a regular function you can call. So you could can just call the spawn function from inside the if block. (it won't count as a separate move for that matter, though, but just run the function body)
Just be aware that due to the use of immer you might have inner mutation of your gamestate. So the order of invocations matters. After your call tree is done there will be an immutable state update with all the changes you've made, handled by boardgame.io.