Navigation

  • Recent
  • Tags
  • Users
  • Search
  • Login
Colyseus
  • Login
  • Search
  • Recent
  • Tags
  • Users

Documentation GitHub

We're migrating to GitHub Discussions. This forum does not accept new registrations since April 6, 2023.
  1. Home
  2. kotwys
kotwys

kotwys

@kotwys

Chat Follow Unfollow
1
Reputation
3
Posts
1.3k
Profile views
0
Followers
0
Following
Joined 19 Sept 2020, 10:41 Last Online 6 Jun 2021, 12:31
Location Izh kar

  • Profile
  • More
    • Continue chat with kotwys
    • Flag Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups
kotwys Follow

Posts made by kotwys

RE: room.OnMessage not registered for Schema message: MyMessage

The message itself contains only data so it isn’t used to detect the message type (you’re trying to catch “readyToStart” messages, right?).

I don’t know how Unity client works but as I could understand it separates messages by classes names if not specified. So maybe this should look like this:

room.OnMessage<MyMessage>("MyMessage", (message) => {
  // your code
});
posted in Questions & Help • 21 Sept 2020, 19:40
RE: MapSchema items don't get to the client

Okay, then I’ll wait. I ran ahead a little :)

Thank you @endel for you work!

posted in Questions & Help • 19 Sept 2020, 16:00
MapSchema items don't get to the client

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.

posted in Questions & Help • 19 Sept 2020, 11:20

© 2023 Endel Dreyer