-
Currently the
As an aside: I'm probably not doing this right, but since each player is a specific color, I want to use the player property |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey @shamseen the const game = {
plugins: [
PluginPlayer({
setup: () => ({ score: 0 }),
})
],
moves: {
updateScore: (G, ctx, newScore) => {
// Get the stored values for the current player.
const playerState = ctx.player.get();
// Update some property.
playerState.score = newScore;
// Store the updated state.
ctx.player.set(playerState);
}
}
}; Then from your board you would do To display player data from your board, you need to access {
players: {
0: { score: 50 },
1: { score: 0 },
},
} As a side note: I personally find this API a bit fiddly. I prefer storing player data manually in the main game state const game = {
setup: (ctx) => {
let initialState = {
players: {},
};
for (let i = 0; i < ctx.numPlayers; i++) {
players[i] = { score: 0 };
}
return initialState;
},
moves: {
updateScore: (G, ctx, newScore) => {
// Update some player state:
G.players[ctx.currentPlayer].score = newScore;
}
}
}; You’d still call |
Beta Was this translation helpful? Give feedback.
Hey @shamseen the
get
/set
referred to in the plugin documentation are in moves. For example:Then from your board you would do
moves.updateScore(50)
or whatever to update that bit of player state.To display player data from your board, you need to access
plugins.player.data
, which will be a plain obj…