Open WeylonSantana opened 8 months ago
I encountered a problem where game states were being shared between different game rooms in Colyseus. The root cause was that variables such as NORMAL_PATH, BOT_LEFT_GOAL, TOP_LEFT_GOAL, BOT_RIGHT_GOAL, and TOP_RIGHT_GOAL were defined as constant arrays, and they were being shared across all rooms. To fix this issue, I ensured that each game room has its own independent instance of these variables. Instead of using shared constants, I created new instances of the arrays for each room when the game is initialized. For example, you can clone arrays using methods like Array.from() or the spread operator to ensure each room has its own copy: This approach prevents multiple rooms from sharing the same array instance, avoiding potential overwrites or conflicts between different game sessions.
I think my solution can be help you
Context
I'm getting this uncaught error on client side, caused by a Map Schema (or a map inside another map maybe)
Bug description
obtain instances of schemas through map get, and modify their values (or in my case, specifically the
name: string
orrevealed:boolean
value, causes an error on the client side, it is not even necessary to send a packet to the client, the error happens instantly when modifying the propertyReproduction
i have this code
Environment & Versions
Colyseus.js: 0.15.17
Workarounds
When obtaining the instance of schema through get
do not change its values
instead
const targetCard = targetPlayer?.cards.get(target.cardId);
targetCard.name = this.state.deck.shift()!
do a re-set of value again, my solution:
targetPlayer?.cards.set(target.cardId, new Card(this.state.deck.shift()!, false));
with that i have no problems for now.