I have noticed that ctx.events has not yet been bound in the first onTurnBegin. I wonder when events are set in ctx. Is this a bug?
onTurnBegin (G, ctx) {
console.log (ctx.events)
// result
// (in the first turn) undefined
// (from the second turn) {endTurn: [Function]}
return G
}
This was a bug that was fixed recently. Which version are you using?
boardgame.io
0.24.0
$ head node_modules/boardgame.io/package.json
{
"name": "boardgame.io",
"version": "0.24.0",
"description": "library for turn-based games",
"repository": "https://github.com/google/boardgame.io",
"scripts": {
"dev": "cross-env NODE_ENV=development babel-watch --presets es2015 examples/react/server.js",
"docsify": "docsify serve docs",
"docsify:update": "node ./scripts/docsify-update.js",
"examples": "npm run dev",
this is code block
flow: {
onTurnBegin(G, ctx) {
console.log('--[ start ] --')
console.log (ctx.events) // this emit "undefined"
return G
},
}
Ah, looks like the bug was not fixed correctly the last time (it only added the Random API, and not the Events API to the first onTurnBegin). Will fix this. Thanks for the report!
Fixed in 1a247919b0f28934e354e7a3dd377db4f161c60a and should be available in 0.24.1.
Most helpful comment
Fixed in 1a247919b0f28934e354e7a3dd377db4f161c60a and should be available in 0.24.1.