I can not believe I didn't noticed the version mismatch!
Updating both server and client to 0.15 has done the job.
Thankyou for your time
I can not believe I didn't noticed the version mismatch!
Updating both server and client to 0.15 has done the job.
Thankyou for your time
Hi, I've been following the Colyseus Phaser tutorial, my issue is in relation to step 7: https://learn.colyseus.io/phaser/1-basic-player-movement.html#listening-for-state-changes
I am receive the error: TypeError: this.room.state.players.onAdd is not a function
My client side create():
async create() {
console.log("Joining room...");
try {
this.room = await this.client.joinOrCreate("my_room");
console.log("Joined Room");
} catch (e) {
console.error(e);
}
this.room.state.players.onAdd((player: any, sessionId: any) => {
//
// A player has joined!
//
console.log("A player has joined! Their unique session id is", sessionId);
});
}
My server side RoomState:
// MyRoomState.ts
import { MapSchema, Schema, type } from "@colyseus/schema";
export class Player extends Schema {
@type("number") x: number;
@type("number") y: number;
}
export class MyRoomState extends Schema {
@type({ map: Player }) players = new MapSchema<Player>();
}
And lastly (the relevant parts of) OnJoin:
onJoin(client: Client, options: any) {
console.log(client.sessionId, "joined");
const mapWidth = 200;
const mapHeight = 300;
// create Player instance
const player = new Player();
// place Player at a random position
player.x = (Math.random() * mapWidth);
player.y = (Math.random() * mapHeight);
// place player in the map of players by its sessionId
// (client.sessionId is unique per connection!)
this.state.players.set(client.sessionId, player);
}
Any guidance appreciated !