Description
I'm implementing a game like Fall Guys, where I used to replace the state
of the room as I transitioned from a minigame to another.
Each room state has its own properties and logic. It seemed to work fine.
Then, I started adding new complex properties (mainly Map
properties) and something went wrong.
In particular, I had some issues with a couple of Map
properties that were defined in both the previous state and the new state.
I used to initialize the new state by assigning the previous cloned property, as follows:
export class PlayerState extends Schema
{
@type("string")
public username: string;
@type("string")
public skin: string;
[...]
}
export class PositionState extends Schema
{
@type("number")
public x: number;
@type("number")
public y: number;
[...]
}
export class NewState extends Schema
{
@type({ map: PlayerState })
public players: MapSchema<PlayerState>
@type({ map: PositionState })
public positions: MapSchema<PositionState>
public constructor(state: PreviousState)
{
this.players = state.players.clone()
this.positions = state.positions.clone()
}
}
After switching from one minigame to the next, replacing the state from the previous to the new one and once sent to the client, I ended up with a mixed state, somehow weird... I found username
/ skin
properties inside positions
map for some players and x
/ y
inside players
for some others...
Now... I'm not sure where the problem actually is...
I would say, not on the server-side since every time I logged those properties on the server-side, they always seemed to be fine...
I guess the issue is on the client-side... Maybe where state binary updates are handled...
Not sure if this problem appears only with Construct 3 plugin or also with Colyseus.js in general... 🤔