<?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[Listen to state not getting proper data [Unity Client]]]></title><description><![CDATA[<p>My state is like this:</p>
<p>onInit(options)</p>
<pre><code>this.maxClients = 5;
this.minClients = 3;

this.setState({
  players: {},
  apid: [],
  dpid: [1, 2, 3, 4, 5],
}); 
</code></pre>
<p>onJoin(client, options) {</p>
<pre><code>var id;
id = this.state.dpid.shift();
this.state.apid.push(id);

this.state.players[client.sessionId] = {
  playerId: id,
  cards: [],
  state: 1,
  pack: 0,
  trickData: {
    Rank: 0,
    Sum: 0,
    c1: 0,
    c2: 0,
    c3: 0
  }
}
</code></pre>
<p>C# code for listen to state change is:</p>
<p>room.Listen(&quot;players/:id&quot;, OnPlayerChange);<br />
<a href="//room.Listen">//room.Listen</a>(&quot;players/:id/:playerId&quot;, OnPlayerIdChange);<br />
<a href="//room.Listen">//room.Listen</a>(&quot;players/:id/:pack&quot;, OnPlayerPack);<br />
room.Listen(&quot;players/:id/:cards/:number&quot;, OnCardsChange);</p>
<p>Problem is when palyersId change the OnPlayerIdChange and OnPlayerPack both getting the this data of state</p>
<pre><code>  trickData: {
    Rank: 0,
    Sum: 0,
    c1: 0,
    c2: 0,
    c3: 0
  }
</code></pre>
<p>i want to listen to only playerId and pack when this variable changes</p>
]]></description><link>http://discuss.colyseus.io/topic/190/listen-to-state-not-getting-proper-data-unity-client</link><generator>RSS for Node</generator><lastBuildDate>Thu, 12 Mar 2026 17:38:21 GMT</lastBuildDate><atom:link href="http://discuss.colyseus.io/topic/190.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 29 Dec 2018 05:22:30 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Listen to state not getting proper data [Unity Client] on Invalid Date]]></title><description><![CDATA[<p>My state is like this:</p>
<p>onInit(options)</p>
<pre><code>this.maxClients = 5;
this.minClients = 3;

this.setState({
  players: {},
  apid: [],
  dpid: [1, 2, 3, 4, 5],
}); 
</code></pre>
<p>onJoin(client, options) {</p>
<pre><code>var id;
id = this.state.dpid.shift();
this.state.apid.push(id);

this.state.players[client.sessionId] = {
  playerId: id,
  cards: [],
  state: 1,
  pack: 0,
  trickData: {
    Rank: 0,
    Sum: 0,
    c1: 0,
    c2: 0,
    c3: 0
  }
}
</code></pre>
<p>C# code for listen to state change is:</p>
<p>room.Listen(&quot;players/:id&quot;, OnPlayerChange);<br />
<a href="//room.Listen">//room.Listen</a>(&quot;players/:id/:playerId&quot;, OnPlayerIdChange);<br />
<a href="//room.Listen">//room.Listen</a>(&quot;players/:id/:pack&quot;, OnPlayerPack);<br />
room.Listen(&quot;players/:id/:cards/:number&quot;, OnCardsChange);</p>
<p>Problem is when palyersId change the OnPlayerIdChange and OnPlayerPack both getting the this data of state</p>
<pre><code>  trickData: {
    Rank: 0,
    Sum: 0,
    c1: 0,
    c2: 0,
    c3: 0
  }
</code></pre>
<p>i want to listen to only playerId and pack when this variable changes</p>
]]></description><link>http://discuss.colyseus.io/post/619</link><guid isPermaLink="true">http://discuss.colyseus.io/post/619</guid><dc:creator><![CDATA[hardik_sl]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Listen to state not getting proper data [Unity Client] on Sat, 29 Dec 2018 13:41:03 GMT]]></title><description><![CDATA[<p>Hi <a class="plugin-mentions-user plugin-mentions-a" href="http://discuss.colyseus.io/uid/136">@hardik_sl</a>! When you specify a segment starting with <code>:attrName</code>  in the listeners, it will actually match any attribute, and assign the attribute name in the <code>change.path.attrName</code> variable.</p>
<p>To listen for a particular value, you can specify it directly, without starting with <code>:</code>. Example:</p>
<pre><code>room.Listen(&quot;players/:id/playerId&quot;, OnPlayerIdChange);
room.Listen(&quot;players/:id/pack&quot;, OnPlayerPack);
</code></pre>
<p>BTW, I see you have an array of <code>cards</code> there. I wouldn't recommend mutating arrays in the room's state, unless you use them as a stack - and just <code>push</code> and <code>pop</code> on them. It's very tricky to keep the client state correct when removing or inserting values in-between the array.</p>
<p>Hope this helps! Cheers!</p>
]]></description><link>http://discuss.colyseus.io/post/621</link><guid isPermaLink="true">http://discuss.colyseus.io/post/621</guid><dc:creator><![CDATA[endel]]></dc:creator><pubDate>Sat, 29 Dec 2018 13:41:03 GMT</pubDate></item><item><title><![CDATA[Reply to Listen to state not getting proper data [Unity Client] on Invalid Date]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="http://discuss.colyseus.io/uid/1">@endel</a> thank you. and i am just using cards array for push and pop only i am not mutating and thanks again for help.</p>
]]></description><link>http://discuss.colyseus.io/post/625</link><guid isPermaLink="true">http://discuss.colyseus.io/post/625</guid><dc:creator><![CDATA[hardik_sl]]></dc:creator><pubDate>Invalid Date</pubDate></item></channel></rss>