Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to dispatch move from another move automatically? #1085

Open
ghost opened this issue Jul 22, 2022 · 1 comment
Open

How to dispatch move from another move automatically? #1085

ghost opened this issue Jul 22, 2022 · 1 comment
Labels

Comments

@ghost
Copy link

ghost commented Jul 22, 2022

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.

@vdfdev vdfdev added the question label Oct 7, 2022
@on3iro
Copy link
Contributor

on3iro commented Jan 18, 2023

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants