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

Calling a move when a phase begins #1145

Closed
sridharraman opened this issue Apr 12, 2023 · 6 comments
Closed

Calling a move when a phase begins #1145

sridharraman opened this issue Apr 12, 2023 · 6 comments

Comments

@sridharraman
Copy link

Hi, I have a game with the following phases:

  1. initialSetup
  2. annualWork
  3. performEOY

The game starts with everyone in phase 1, then they go to phase 2 at each time step. At the end of each phase 2, the game needs to make some calculations (e.g. updating budgets for players, etc.); so I have that as a separate phase (performEOY) with only one move: calculateEOY. Is there a way for me to call this move from the onBegin section of the performEOY phase?

This third phase is basically an automatic phase for running backend queries. Any ideas on how best to do this?

@webrunner42
Copy link

instead of performing the eoy stuff in a move, you can just put it in the onEnd of annualWork.

alternatively you can make the client just auto do the move for you once it detects you're in that phase.

@sridharraman
Copy link
Author

instead of performing the eoy stuff in a move, you can just put it in the onEnd of annualWork

Is it possible to access moves inside onEnd? I wasn't able to access the method.

@webrunner42
Copy link

instead of performing the eoy stuff in a move, you can just put it in the onEnd of annualWork

Is it possible to access moves inside onEnd? I wasn't able to access the method.

You don't need the move- you can just directly do what the move does. If your moves are already separate functions you can just call it

@sridharraman
Copy link
Author

I am unable to access the move functions inside onBegin or onEnd. This is a sample phase I have:

export const testPromptPhase: PhaseConfig<SelcoGameState> = {
  moves: {
    showMsg,
    performAction,
  },
  onBegin: ({ G, ctx, }) => {
    console.log('beginning testPromptPhase')
    showMsg({ G, ctx },)
  }, 
}

This is the typescript error I get:

This expression is not callable.
  Not all constituents of type 'Move<GameState, Record<string, unknown>>' are callable.
    Type 'LongFormMove<GameState, Record<string, unknown>>' has no call

@webrunner42
Copy link

webrunner42 commented Apr 18, 2023

What I did for things that sometimes were automatic and sometimes werent was more like:

function doEndTurnThings(G,ctx,events)
{
//perform eoy
}
const myMove: Move<CMCGameState> = ({ G, ctx, events }) => {
  return doEndTurnThings(G,ctx,events);
};

...

// in game def
moves: {
myMove: myMove
}

onEnd(G,ctx,events){
doEndTurnThings()
}

in your use case yoiu mnay noit even need to do the move itself-:

moves {}
onEnd(g,ctx,events) {
doendturnthings(G,ctx,events)
events.endturn()
}

@sridharraman
Copy link
Author

Thanks, @webrunner42 . That worked.

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

No branches or pull requests

2 participants