Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Cristian Da Silva
    @cristiands7
    Generators are not serializable, but it is possible to store the initial state and next arguments, so that the state of a generator can be replicated. It is necessary that the functions used do not have side effects (a condition that is currently also necessary, so it would not be a problem).
    Babel's transpiled code for a generator may be helpful for what you have in mind. I was reviewing it but opted for a simpler approach.
    Chris Swithinbank
    @delucis
    Or maybe it’s a case for some code generation, where you write your skills as some nicely expressed syntax, but it gets transformed into the stages etc.:
    const useAbility = {
      name: 'useAbility',
      actions: [
        (G, ctx) => {},
        (G, ctx) => {},
        (G, ctx) => {},
      ]
    };
    
    const makeStages = (skill) => {
      const stages = {};
      for (let i = 0; i < skill.actions.length; i++) {
        const stage = `${skill.name}-${i}`;
        stages[stage] = {
          moves: {
            next: skill.actions[i]
          },
        };
      }
    }
    
    const stages = makeStages(useAbility);
    29 replies
    Cristian Da Silva
    @cristiands7

    Right, but that’s for handling async stuff in a single place

    I think what I want to do can be considered as handling async stuff in a single place.

    Chris Swithinbank
    @delucis
    This would still need some additional stuff for handling active players for each stage. But something like this would allow writing a single “skill” in one place and then still use the bgio game syntax.

    I think what I want to do can be considered as handling async stuff in a single place.

    Oh, yes, definitely — I meant more generally for boardgame.io

    SamyGarib
    @SamyGarib
    This message was deleted

    Hi!. I'm having trouble with the Undo feature.
    I'm getting an error, "ERROR: No moves to undo"., even though there are move registered in the logs.
    I don't know if I understand how undo and moves work.
    I have two moves inside a stage:

    • clickChecker: A checker is clicked, selects target positions (stored in G) and reset previous ones.
    • clickTarget: A target position is clicked, and actually move checkers in the checkers map (stored in G) and reset targets.
      The movements that have to be undone are the one in clickTarget. The first ones are not relevant and are just part of the UX (prividing buttons for valid movements).
      But anyways, none are responding to de undo action. When I see the logs, I see all moves, but going thru them actually does nothing,
      I just can see the initial state and the last state (current). I know something is wrong because I see a working-history for moves in a previous phase.

    This is my implementation.

    phases: {
        defineWhoStarts: {  
            moves: { /* This are well registered! */}
        },
        play: {
            stages: {
                moveCheckers: {
                    moves: {
                        /* This aren't registered for undo? */
                        clickChecker: {}
                        clickTarget: {}
                    }
                }
            }
        }
    }
    9 replies
    SamyGarib
    @SamyGarib
    In this case, If I have an endpoint in the server, how can I access a match data from there?
    server.router.get('/custom-endpoint', (ctx, next) => {
      ctx.body = 'Hello World!';
      /* Accesss Data from a game matchID G object */
    });
    4 replies
    Fladrif
    @Fladrif
    Hi, first off thanks for maintaining this project, it's been great! I've run into a problem currently with the server router that is being exposed and a subsequent example. At the end of the server doc https://boardgame.io/documentation/#/api/Server there's an example with adding middleware for an existing route created by the boardgame.io server. I tried implementing an auth middleware to cover the /games route as shown in the example, but as far as I can tell the middleware is never run because the get func for /games is instantiated before the server.router.use('/games', authFunc) call so it'll never be run. Am I doing something wrong here? Thanks!
    15 replies
    SamyGarib
    @SamyGarib

    Calling an external shell command as part of a move, and storing the results in G.

    Hopefully, this is the last issue I have before I can finish implementing my game with this framework. It is so awesome.
    Maybe this is the time to have a (paid) video chat with someone that could help me with this, and some other minor issues regarding the AI module, Undo, and maybe some Vue tips for problems I have.

    I have come across this problem I haven't been able to solve by myself, maybe because I lack knowledge of NodeJS.
    I have a library with AI and some tools to calculate some game boundaries, written in C. Before I change the stage, I have to call it on every dice roll and store its results in G.

    I made a custom endpoint in the server that handles that, and a wrapper function, and I call it in the move. But it is an async function, and the callback function does not have the context. If I bind the G object,
    when I try to write to it, I get a proxy revoked error.

    moves: {
        /* Roll the Dice Set. */
        clickRoll: (G,ctx,matchID) => {      
            G.diceRoll = [ctx.random.D6(),ctx.random.D6()];
            let context={G:G,ctx:ctx}
            abakLib.readFromIA(matchID,0).then((function (result) {
              let jsonRes = JSON.parse(result);
              /* I need to pass jsonRes.maxMovements to the G object Here.*/
            }).bind(context)).catch(function(error) {
                console.log("Coudnt Read FROM AI");console.log(error)
        });       
    }

    I think a plugin maybe my solution here, but docs weren't enough for me to understand how to make it work. And I'm not even sure I'm will not have the exact same problem, but within the plugin.

    6 replies
    fuenfundachtzig
    @fuenfundachtzig
    Hi everyone and thanks for providing this great framework! I just opened a pull request to have a clone of Qwirkle implemented using boardgame.io added to the list of example projects. The game is in a fairly advanced state what concerns the graphics and the game logic is fully implemented. But the lobby is very basic (both in design and functionality), and also at the moment I keep the server and client software in two separate repositories because one depends on react and the other doesn't. (I guess this could be stream-lined but I haven't managed. It works but is certainly not the best solution as the game logic needs to be kept in sync between the two repositories, of course.) In any case, I'd be happy if you accept the merge request, and even more importantly I am looking for people who like the game and would be interested to improve the code basis -- a call for help basically :)
    Chris Swithinbank
    @delucis
    @fuenfundachtzig Have you seen https://www.freeboardgames.org/? They have a bunch of infrastructure around boardgame.io games so if you’re more interested in implementing the game without worrying too much about the lobby etc., that might be an interesting option. They have a pretty active Discord channel too: https://discord.com/invite/AaE6n3n
    With regards to splitting things into two separate repositories, one pattern that is sometimes easier to work with is to have a single “monorepo” with frontend, server, and shared packages. That way you can have the game implementation in shared and have both the React frontend and the server backend depend on it.
    5 replies
    Did you find Babylon.js & boardgame.io integrated nicely together?
    Alex Jurkiewicz
    @alexjurkiewicz
    I want to update my react component's state at the start of each turn. How can I do this? I see there is Game.turn.onBegin, how can I hook my component into this?
    Chris Swithinbank
    @delucis
    @alexjurkiewicz You should be able to do this with a React useEffect hook (in a function component) or componentDidUpdate lifecycle method (in a class component).
    const Board = ({ ctx }) => {
      const [state, setState] = useState();
      useEffect(() => {
        setState(prevState => prevState);
      }, [ctx.turn]);
    }
    class Board extends React.Component {
      // ...
      componentDidUpdate(prevProps, prevState) {
        if (this.props.ctx.turn > prevProps.ctx.turn) {
          this.setState(prevState);
        }
      }
    }
    Alex Jurkiewicz
    @alexjurkiewicz:matrix.org
    [m]
    doh, of course, thanks
    Alex Jurkiewicz
    @alexjurkiewicz:matrix.org
    [m]
    The way ctx.random is typed as Ctx.random?: RandomAPI | undefined is a little awkward. I guess it's because random is implemented as a plugin and the user could technically not load it?
    Chris Swithinbank
    @delucis
    @alexjurkiewicz:matrix.org It’s because Ctx currently has two states: 1) in moves where ctx.random, ctx.events etc. and other plugins exist and 2) on the client where it is a plain object without those plugin APIs attached. To address this we’re going to move away from attaching plugins to ctx and instead attach them directly to a single object that moves receive, like ({ G, ctx, random, ... }) => {} (see boardgameio/boardgame.io#891). It’s a significant breaking change, so I’ve been hanging back from merging it, but it fixes this and a few other Typescript issues nicely.
    (There isn’t really a way to not load the default plugins currently, although loading a blank { name: 'random' } plugin would overwrite the default plugin. Not sure we would need to worry about that too much in our types though.)
    Alex Jurkiewicz
    @alexjurkiewicz:matrix.org
    [m]
    gotcha! Would it make sense to create a CtxServer and CtxClient typing? That could also fix the issue without needing a breaking change, right?
    Chris Swithinbank
    @delucis
    It might — although IIRC that results in a lot of coercing back and forth internally, but if it’s a simple change, that would be nice as a stop-gap.
    Alex Jurkiewicz
    @alexjurkiewicz:matrix.org
    [m]

    from a user perspective, it worked well:

    interface GameCtx extends Ctx {
      random: RandomAPI
    }
    
    export const MyGame: Game<MyGameState, MyGameCtx, MyGameSetupData> = { ... }

    fixed up typing warnings on the server, and on the client:

    export interface IBoardProps extends BoardProps<IInvasionState> {
      ctx: Omit<Ctx, 'random'>
    }
    export class InvasionBoard extends React.Component<IBoardProps, IBoardState> { ... }

    Did the same. Would you be interested in a PR to make this official?

    2 replies
    also, how is it intended that the Game returns information to the client about invalid moves? It seems like if a move returns INVALID_MOVE, any modifications to G aren't saved
    3 replies
    JasonCzd
    @JasonCzd
    Hey all.. awesome framework here.. Using the remote server option, I was prototyping a game idea that requires some player moves, followed by a simulation round that would essentially mutate parts of the game state (G) based on the player input. As the changes are happening, I want the state changes rebroadcast on the sockets so the clients can see in real time the changes that are happening, but it seems like the socket communication is only triggered by explicit method invocations form a client on one of the turns methods.. Any insights, or am I missing something? Thanks!!
    9 replies
    Anurat Chapanond
    @anurat
    Hello, just found boardgame.io, awesome project!, I wonder if there is any resources to use vue.js as frontend instead of react.js? much appreciated.
    4 replies
    Sise
    @allex-sise
    Hi, I have an issue ending the game. Simplified: "endIf: (G) => true" , but when checking for ctx.gameover it remains undefined. Is there something that I am missing out?
    1 reply
    Stephen Shilale
    @sshilal1
    I am having trouble accessing the playerName's that players set up when they join the game. I would like to display the other players names on multiplayer games and I cant seem to find playerNames anywhere in the ctx
    12 replies
    SamyGarib
    @SamyGarib
    Hi. I'm working on saving the results to the games/matches to an external database after a game is finished. Inside a move, or the onbegin/onend event, is there a way to retrieve the matchID of that game ?, it is not in the ctx. I could pass an external ID in setup data, but I think it should be a more elegant way. Thanks!.
    4 replies
    SamyGarib
    @SamyGarib
    Another question. I would like to have a visitor feature, when many people can watch a game that is being played. I'm pretty sure the lobby feature will reject a petition to connect when to players are in in a two player game, and if I increase the number of players, I would have to tamper the turns system, and that is not very elegant. So, is there a way to achieve this ?
    15 replies
    rateforx
    @rateforx
    What is the difference between ctx.playerID and ctx.currentPlayer?
    2 replies
    rateforx
    @rateforx
    And why the playerID can be undefined?
    Chris Swithinbank
    @delucis
    @rateforx ctx.currentPlayer is the player whose turn it is currently. ctx.playerID is only available in move functions and indicates who is making the move. Usually ctx.playerID and ctx.currentPlayer will be the same, unless you use Stages, in which case it’s possible to allow players other than currentPlayer to make moves, so you might need playerID to know who moved.
    rateforx
    @rateforx
    Ok, so the playerID is the way to go, thx :)
    Vinny
    @vdfdev:matrix.org
    [m]
    hey folks, it seems like the upgrade from version 0.47.0 to 0.47.1 broke mergers on FBG: freeboardgames/FreeBoardGames.org#930 I've been investigating why on the last few hours, and it seems like the issue is that the new version is ignoring the results of this line: https://github.com/freeboardgames/FreeBoardGames.org/blob/3581aa653430aa8592fb13d7343efcf5bea319b0/web/src/games/mergers/game.ts#L600 ... The game seems to work by the first player choosing and swapping a stock here: https://github.com/freeboardgames/FreeBoardGames.org/blob/3581aa653430aa8592fb13d7343efcf5bea319b0/web/src/games/mergers/game.test.ts#L1025 which is executed on the "mergerPhase". This phase finishes (only one move allowed), which then sends the next player to the chooseChainToMergePhase, which automatically finishes (endIf criteria met), starting the "mergerPhase" again. I left the debugger on the "onBegin" of the "mergerPhase" and it is executed correctly the second time, setting the money to 13200 for the first player and 8000 to the second, as expected. However, the test fails on this line: https://github.com/freeboardgames/FreeBoardGames.org/blob/3581aa653430aa8592fb13d7343efcf5bea319b0/web/src/games/mergers/game.test.ts#L1032, which implies that somehow the framework ignored the change on the G in this case
    here is the diff from 0.47.0 to 0.47.1: https://github.com/boardgameio/boardgame.io/compare/v0.47.0...v0.47.1 I expected it to be mostly about new warnings/errors, but it seems like it changed the behavior somehow of the onBegin of the phase
    Vinny
    @vdfdev:matrix.org
    [m]
    I can try to reproduce this in a smaller example tomorrow
    This might have worked before because we used to call the setPhase in a place which is now forbidden
    But I don't see why it wouldn't work
    Chris Swithinbank
    @delucis
    @vdfdev:matrix.org Have you tried this with 0.47.2 or later? I added stack traces to events errors/warnings in 0.47.2 that may help catch what’s causing this.
    3 replies
    There’s also a summary of which events are now supported in which hooks here: https://boardgame.io/documentation/#/events?id=calling-events-from-hooks
    Vinny
    @vdfdev:matrix.org
    [m]
    The mergers code was calling setPhase on the next turn order thing, I moved it to onEnd of the turn instead
    1 reply
    Vinny
    @vdfdev:matrix.org
    [m]
    Oh, that can be useful for sure!
    SamyGarib
    @SamyGarib
    why this error might be produced ? :
    ERROR: invalid stateID, was=[142], expected=[143] - playerID=[0] - action[clickDone]
    1 reply
    James Shamenski 🦇🔊+ 🐝🫖🌊
    @GladRobot_twitter
    Noob here. I'd like to hire a contractor to make a 5 turn battle game with Boardgame.io. If anyone here has time for a fun project, please ping me on twitter @gladrobot. Thank-you (bow)
    rateforx
    @rateforx
    Is it possible to create a react context that contains up to date BoardProps to avoid props drilling? How can I achieve that with CreateContext api?
    10 replies
    SedMek
    @SedMek
    Hello,
    I am trying to make a personal website for the game: "The mind" where any player is allowed to play, as long as he has cards in his hand, without taking turns.
    I read through the documentation and it seems that there is no straight forward solution that allows this behaviour.
    How can I make a game engine without turns, where any player can play whenever he wants?
    Thank's a lot
    3 replies