Skip to content

How / where do I set player properties with PluginPlayer? #929

Answered by delucis
shamseen asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @shamseen the get/set referred to in the plugin documentation are in moves. For example:

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 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…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by shamseen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #928 on April 09, 2021 20:13.