<?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[How to get arrays on javascript client?]]></title><description><![CDATA[<p>Hey guys!</p>
<p>I just started working with Colysus and liked it a lot!<br />
But there is something I can't understand yet...</p>
<p>This is my Player class:</p>
<pre><code>import { Schema, type } from '@colyseus/schema';

class PlayerState extends Schema {
  @type('number') level: number = 0;
  @type('number') timer: number = 300;
  @type('number') points: number = 0;
  @type('number') errors: number = 0;
  @type('boolean') error: boolean = false;
}

class GameState extends Schema {
  @type(['number'])
  game: number[] = [];
}

export class Player extends Schema {
  @type('string')
  sessionId: string;

  @type('string')
  name: string;

  @type(PlayerState)
  state: PlayerState = new PlayerState();

  @type(GameState)
  gameState: GameState = new GameState();
}
</code></pre>
<p>When I listen to changes on PlayerState, for example, it's ok I get the information:</p>
<pre><code>player.state.onChange = (changes) =&gt; {
    changes.forEach((c) =&gt; {
      this.players[this.getPlayerIndex(key)].state[c.field] = c.value;
    });
};
</code></pre>
<pre><code>[{op: 128, field: &quot;level&quot;, dynamicIndex: undefined, value: 0, previousValue: undefined},
{op: 128, field: &quot;timer&quot;, dynamicIndex: undefined, value: 300, previousValue: undefined},
{op: 128, field: &quot;points&quot;, dynamicIndex: undefined, value: 0, previousValue: undefined},
{op: 128, field: &quot;errors&quot;, dynamicIndex: undefined, value: 0, previousValue: undefined},
{op: 128, field: &quot;error&quot;, dynamicIndex: undefined, value: false, previousValue: undefined}]
</code></pre>
<p>But when get the information from GameState ('game' wich is an array) I get this:</p>
<pre><code>[{op: 128, field: &quot;game&quot;, dynamicIndex: undefined, value: Proxy, previousValue: undefined}]
</code></pre>
<pre><code>Proxy {$changes: ChangeTree, $items: Map(16), $indexes: Map(16), $refId: 0, $proxy: true}
</code></pre>
<p>How can I deal with this 'Proxy'?<br />
I've tried a lot of stuff and nothing works...<br />
I would like to understand how to read it, get the original array from this and get the changes.</p>
<p>Thanks in advance!</p>
]]></description><link>http://discuss.colyseus.io/topic/413/how-to-get-arrays-on-javascript-client</link><generator>RSS for Node</generator><lastBuildDate>Thu, 12 Mar 2026 16:53:33 GMT</lastBuildDate><atom:link href="http://discuss.colyseus.io/topic/413.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 28 Oct 2020 20:43:36 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to get arrays on javascript client? on Invalid Date]]></title><description><![CDATA[<p>Hey guys!</p>
<p>I just started working with Colysus and liked it a lot!<br />
But there is something I can't understand yet...</p>
<p>This is my Player class:</p>
<pre><code>import { Schema, type } from '@colyseus/schema';

class PlayerState extends Schema {
  @type('number') level: number = 0;
  @type('number') timer: number = 300;
  @type('number') points: number = 0;
  @type('number') errors: number = 0;
  @type('boolean') error: boolean = false;
}

class GameState extends Schema {
  @type(['number'])
  game: number[] = [];
}

export class Player extends Schema {
  @type('string')
  sessionId: string;

  @type('string')
  name: string;

  @type(PlayerState)
  state: PlayerState = new PlayerState();

  @type(GameState)
  gameState: GameState = new GameState();
}
</code></pre>
<p>When I listen to changes on PlayerState, for example, it's ok I get the information:</p>
<pre><code>player.state.onChange = (changes) =&gt; {
    changes.forEach((c) =&gt; {
      this.players[this.getPlayerIndex(key)].state[c.field] = c.value;
    });
};
</code></pre>
<pre><code>[{op: 128, field: &quot;level&quot;, dynamicIndex: undefined, value: 0, previousValue: undefined},
{op: 128, field: &quot;timer&quot;, dynamicIndex: undefined, value: 300, previousValue: undefined},
{op: 128, field: &quot;points&quot;, dynamicIndex: undefined, value: 0, previousValue: undefined},
{op: 128, field: &quot;errors&quot;, dynamicIndex: undefined, value: 0, previousValue: undefined},
{op: 128, field: &quot;error&quot;, dynamicIndex: undefined, value: false, previousValue: undefined}]
</code></pre>
<p>But when get the information from GameState ('game' wich is an array) I get this:</p>
<pre><code>[{op: 128, field: &quot;game&quot;, dynamicIndex: undefined, value: Proxy, previousValue: undefined}]
</code></pre>
<pre><code>Proxy {$changes: ChangeTree, $items: Map(16), $indexes: Map(16), $refId: 0, $proxy: true}
</code></pre>
<p>How can I deal with this 'Proxy'?<br />
I've tried a lot of stuff and nothing works...<br />
I would like to understand how to read it, get the original array from this and get the changes.</p>
<p>Thanks in advance!</p>
]]></description><link>http://discuss.colyseus.io/post/1354</link><guid isPermaLink="true">http://discuss.colyseus.io/post/1354</guid><dc:creator><![CDATA[leal32b]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to How to get arrays on javascript client? on Wed, 28 Oct 2020 23:22:38 GMT]]></title><description><![CDATA[<p>Hi <a class="plugin-mentions-user plugin-mentions-a" href="http://discuss.colyseus.io/uid/733">@leal32b</a>, glad you're enjoying using Colyseus so far!</p>
<p>Arrays are accessible on the client-side via a Proxy - you can expect them to have exactly the same methods from a JavaScript Array object, which you can see the documentation here: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array" rel="nofollow">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array</a></p>
<p>If you'd like to debug the values from the array, you can use <code>console.log(Array.from(proxy))</code>. You can access and manipulate the <code>Proxy</code> instance just like a regular though, it just does not print properly via <code>console.log()</code>.</p>
<p>Docs about the <code>ArraySchema</code> can be found here as well: <a href="https://docs.colyseus.io/state/schema/#arrayschema" rel="nofollow">https://docs.colyseus.io/state/schema/#arrayschema</a></p>
]]></description><link>http://discuss.colyseus.io/post/1355</link><guid isPermaLink="true">http://discuss.colyseus.io/post/1355</guid><dc:creator><![CDATA[endel]]></dc:creator><pubDate>Wed, 28 Oct 2020 23:22:38 GMT</pubDate></item><item><title><![CDATA[Reply to How to get arrays on javascript 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> said in <a href="/post/1355">How to get arrays on javascript client?</a>:</p>
<blockquote>
<p>console.log(Array.from(proxy))</p>
</blockquote>
<p>Thanks a lot, endel!! Worked perfectly!<br />
Colyseus rocks! xD</p>
]]></description><link>http://discuss.colyseus.io/post/1356</link><guid isPermaLink="true">http://discuss.colyseus.io/post/1356</guid><dc:creator><![CDATA[leal32b]]></dc:creator><pubDate>Invalid Date</pubDate></item></channel></rss>