<?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[Issue with phaser tutorial]]></title><description><![CDATA[<p>Hi, I've been following the Colyseus Phaser tutorial, my issue is in relation to step 7: <a href="https://learn.colyseus.io/phaser/1-basic-player-movement.html#listening-for-state-changes" rel="nofollow">https://learn.colyseus.io/phaser/1-basic-player-movement.html#listening-for-state-changes</a></p>
<p>I am receive the error: <code>TypeError: this.room.state.players.onAdd is not a function</code></p>
<p>My client side create():</p>
<pre><code>	async create() {
		console.log(&quot;Joining room...&quot;);

		try {
			this.room = await this.client.joinOrCreate(&quot;my_room&quot;);
			console.log(&quot;Joined Room&quot;);
		} catch (e) {
			console.error(e);
		}
		this.room.state.players.onAdd((player: any, sessionId: any) =&gt; {
			//
			// A player has joined!
			//
			console.log(&quot;A player has joined! Their unique session id is&quot;, sessionId);
		});
	}
</code></pre>
<p>My server side RoomState:</p>
<pre><code>// MyRoomState.ts
import { MapSchema, Schema, type } from &quot;@colyseus/schema&quot;;

export class Player extends Schema {
  @type(&quot;number&quot;) x: number;
  @type(&quot;number&quot;) y: number;
}

export class MyRoomState extends Schema {
  @type({ map: Player }) players = new MapSchema&lt;Player&gt;();
}
</code></pre>
<p>And lastly (the relevant parts of) OnJoin:</p>
<pre><code>  onJoin(client: Client, options: any) {
    console.log(client.sessionId, &quot;joined&quot;);
    const mapWidth = 200;
    const mapHeight = 300;

    // create Player instance
    const player = new Player();

    // place Player at a random position
    player.x = (Math.random() * mapWidth);
    player.y = (Math.random() * mapHeight);

    // place player in the map of players by its sessionId
    // (client.sessionId is unique per connection!)
    this.state.players.set(client.sessionId, player);
  }
</code></pre>
<p>Any guidance appreciated !</p>
]]></description><link>http://discuss.colyseus.io/topic/957/issue-with-phaser-tutorial</link><generator>RSS for Node</generator><lastBuildDate>Sun, 08 Mar 2026 00:32:17 GMT</lastBuildDate><atom:link href="http://discuss.colyseus.io/topic/957.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 26 Mar 2023 09:07:39 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Issue with phaser tutorial on Invalid Date]]></title><description><![CDATA[<p>Hi, I've been following the Colyseus Phaser tutorial, my issue is in relation to step 7: <a href="https://learn.colyseus.io/phaser/1-basic-player-movement.html#listening-for-state-changes" rel="nofollow">https://learn.colyseus.io/phaser/1-basic-player-movement.html#listening-for-state-changes</a></p>
<p>I am receive the error: <code>TypeError: this.room.state.players.onAdd is not a function</code></p>
<p>My client side create():</p>
<pre><code>	async create() {
		console.log(&quot;Joining room...&quot;);

		try {
			this.room = await this.client.joinOrCreate(&quot;my_room&quot;);
			console.log(&quot;Joined Room&quot;);
		} catch (e) {
			console.error(e);
		}
		this.room.state.players.onAdd((player: any, sessionId: any) =&gt; {
			//
			// A player has joined!
			//
			console.log(&quot;A player has joined! Their unique session id is&quot;, sessionId);
		});
	}
</code></pre>
<p>My server side RoomState:</p>
<pre><code>// MyRoomState.ts
import { MapSchema, Schema, type } from &quot;@colyseus/schema&quot;;

export class Player extends Schema {
  @type(&quot;number&quot;) x: number;
  @type(&quot;number&quot;) y: number;
}

export class MyRoomState extends Schema {
  @type({ map: Player }) players = new MapSchema&lt;Player&gt;();
}
</code></pre>
<p>And lastly (the relevant parts of) OnJoin:</p>
<pre><code>  onJoin(client: Client, options: any) {
    console.log(client.sessionId, &quot;joined&quot;);
    const mapWidth = 200;
    const mapHeight = 300;

    // create Player instance
    const player = new Player();

    // place Player at a random position
    player.x = (Math.random() * mapWidth);
    player.y = (Math.random() * mapHeight);

    // place player in the map of players by its sessionId
    // (client.sessionId is unique per connection!)
    this.state.players.set(client.sessionId, player);
  }
</code></pre>
<p>Any guidance appreciated !</p>
]]></description><link>http://discuss.colyseus.io/post/2387</link><guid isPermaLink="true">http://discuss.colyseus.io/post/2387</guid><dc:creator><![CDATA[kayyos]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Issue with phaser tutorial on Invalid Date]]></title><description><![CDATA[<p>Hi <a class="plugin-mentions-user plugin-mentions-a" href="http://discuss.colyseus.io/uid/4765">@kayyos</a>, please make sure to run the same version on the server and client, they both should be either 0.14 or 0.15.</p>
<p>Currently 0.15 is on preview, so you can fix this by installing 0.15@preview on the client-side:</p>
<pre><code>npm install colyseus.js@preview --save
</code></pre>
<p>Hope this helps, cheers!</p>
]]></description><link>http://discuss.colyseus.io/post/2390</link><guid isPermaLink="true">http://discuss.colyseus.io/post/2390</guid><dc:creator><![CDATA[endel]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Issue with phaser tutorial on Invalid Date]]></title><description><![CDATA[<p>I can not believe I didn't noticed the version mismatch!</p>
<p>Updating both server and client to 0.15 has done the job.</p>
<p>Thankyou for your time</p>
]]></description><link>http://discuss.colyseus.io/post/2396</link><guid isPermaLink="true">http://discuss.colyseus.io/post/2396</guid><dc:creator><![CDATA[kayyos]]></dc:creator><pubDate>Invalid Date</pubDate></item></channel></rss>