Calling a move when a phase begins
sridharraman opened this issue · 7 comments
Hi, I have a game with the following phases:
- initialSetup
- annualWork
- 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?
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.
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.
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
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
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()
}
Thanks, @webrunner42 . That worked.