<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[MapSchema items don&#x27;t get to the client]]></title><description><![CDATA[<p>Hello, It’s the first time I’m using Colyseus and I ran into problem.</p>
<p>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.</p>
<p>I have a <code>MapSchema</code> in state. Whenever I update the map, it <em>gets updated</em> properly on the server and <code>onStateChanged</code> event is raised on the client, but the map on the client itself remains empty and consequently <code>on{Add,Remove}</code> events don’t appear.</p>
<p>I have the following code:</p>
<h3>Room handler</h3>
<pre><code class="language-haxe">import kakto.common.schema.WalkableState;

class Walkable extends Room {
  override function onCreate(o:Map&lt;String, Dynamic&gt;) {
    setState(new WalkableState());
  }

  override function onJoin(client:Client, ?o:Map&lt;String, Dynamic&gt;, ?auth:Dynamic) {
    (state:WalkableState).players.set(client.sessionId, new Player());
    return null;
  }
}
</code></pre>
<h3>Schema</h3>
<p>Schema file is common for both client and server with packages changed using conditional compilation. Maybe this is the root of the problem?</p>
<pre><code class="language-haxe">#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&lt;Player&gt;();

  #if hxnodejs
  public function new() {}
  #end
}
</code></pre>
<h3>Client</h3>
<pre><code class="language-haxe">room.onStateChange += (state:WalkableState) -&gt; {
  trace(state.players); // always empty Map
};

// these two don't get called at all
room.state.players.onAdd = (player, id) -&gt; {
  trace('$id joined');
};

room.state.players.onRemove = (player, id) -&gt; {
  trace('$id quit');
};
</code></pre>
<p>Thanks.</p>
]]></description><link>http://discuss.colyseus.io/topic/398/mapschema-items-don-t-get-to-the-client</link><generator>RSS for Node</generator><lastBuildDate>Fri, 09 Oct 2026 22:23:06 GMT</lastBuildDate><atom:link href="http://discuss.colyseus.io/topic/398.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 19 Sep 2020 11:20:48 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to MapSchema items don&#x27;t get to the client on Sat, 19 Sep 2020 11:27:46 GMT]]></title><description><![CDATA[<p>Hello, It’s the first time I’m using Colyseus and I ran into problem.</p>
<p>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.</p>
<p>I have a <code>MapSchema</code> in state. Whenever I update the map, it <em>gets updated</em> properly on the server and <code>onStateChanged</code> event is raised on the client, but the map on the client itself remains empty and consequently <code>on{Add,Remove}</code> events don’t appear.</p>
<p>I have the following code:</p>
<h3>Room handler</h3>
<pre><code class="language-haxe">import kakto.common.schema.WalkableState;

class Walkable extends Room {
  override function onCreate(o:Map&lt;String, Dynamic&gt;) {
    setState(new WalkableState());
  }

  override function onJoin(client:Client, ?o:Map&lt;String, Dynamic&gt;, ?auth:Dynamic) {
    (state:WalkableState).players.set(client.sessionId, new Player());
    return null;
  }
}
</code></pre>
<h3>Schema</h3>
<p>Schema file is common for both client and server with packages changed using conditional compilation. Maybe this is the root of the problem?</p>
<pre><code class="language-haxe">#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&lt;Player&gt;();

  #if hxnodejs
  public function new() {}
  #end
}
</code></pre>
<h3>Client</h3>
<pre><code class="language-haxe">room.onStateChange += (state:WalkableState) -&gt; {
  trace(state.players); // always empty Map
};

// these two don't get called at all
room.state.players.onAdd = (player, id) -&gt; {
  trace('$id joined');
};

room.state.players.onRemove = (player, id) -&gt; {
  trace('$id quit');
};
</code></pre>
<p>Thanks.</p>
]]></description><link>http://discuss.colyseus.io/post/1317</link><guid isPermaLink="true">http://discuss.colyseus.io/post/1317</guid><dc:creator><![CDATA[kotwys]]></dc:creator><pubDate>Sat, 19 Sep 2020 11:27:46 GMT</pubDate></item><item><title><![CDATA[Reply to MapSchema items don&#x27;t get to the client on Invalid Date]]></title><description><![CDATA[<p>Hi <a class="plugin-mentions-user plugin-mentions-a" href="http://discuss.colyseus.io/uid/719">@kotwys</a>, welcome 👋</p>
<p>The version 0.14 is not yet implemented in Haxe, if you're interested in migrating to 0.14 because of the &quot;none&quot; serializer, I'd suggest using the workaround instead - which is to use a dummy schema as your room state:</p>
<pre><code>class State extends Schema {
  @type(&quot;string&quot;) dummy: string;
}

// ...
onCreate() {
  this.setState(new State())
}
</code></pre>
<p>I'll let you know here once the new schema decoder is available in Haxe, it's probably going to happen next month!</p>
<p>Cheers</p>
]]></description><link>http://discuss.colyseus.io/post/1319</link><guid isPermaLink="true">http://discuss.colyseus.io/post/1319</guid><dc:creator><![CDATA[endel]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to MapSchema items don&#x27;t get to the client on Invalid Date]]></title><description><![CDATA[<p>Okay, then I’ll wait. I ran ahead a little :)</p>
<p>Thank you <a class="plugin-mentions-user plugin-mentions-a" href="http://discuss.colyseus.io/uid/1">@endel</a> for you work!</p>
]]></description><link>http://discuss.colyseus.io/post/1320</link><guid isPermaLink="true">http://discuss.colyseus.io/post/1320</guid><dc:creator><![CDATA[kotwys]]></dc:creator><pubDate>Invalid Date</pubDate></item></channel></rss>