Hello, It’s the first time I’m using Colyseus and I ran into problem.
The code for both client and server is written with Haxe. Also I had to switch to alpha 0.14 because Haxe client didn't tolerate “none” states on 0.13.
I have a MapSchema
in state. Whenever I update the map, it gets updated properly on the server and onStateChanged
event is raised on the client, but the map on the client itself remains empty and consequently on{Add,Remove}
events don’t appear.
I have the following code:
Room handler
import kakto.common.schema.WalkableState;
class Walkable extends Room {
override function onCreate(o:Map<String, Dynamic>) {
setState(new WalkableState());
}
override function onJoin(client:Client, ?o:Map<String, Dynamic>, ?auth:Dynamic) {
(state:WalkableState).players.set(client.sessionId, new Player());
return null;
}
}
Schema
Schema file is common for both client and server with packages changed using conditional compilation. Maybe this is the root of the problem?
#if hxnodejs
import colyseus.server.schema.Schema;
#else
import io.colyseus.serializer.schema.Schema;
import io.colyseus.serializer.schema.MapSchema;
#end
class Player extends Schema {}
class WalkableState extends Schema {
// There may be anything instead of `Player` type
#if hxnodejs
@:type({ map: Player })
#else
@:type('map', Player)
#end
public var players = new MapSchema<Player>();
#if hxnodejs
public function new() {}
#end
}
Client
room.onStateChange += (state:WalkableState) -> {
trace(state.players); // always empty Map
};
// these two don't get called at all
room.state.players.onAdd = (player, id) -> {
trace('$id joined');
};
room.state.players.onRemove = (player, id) -> {
trace('$id quit');
};
Thanks.