<?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 push a variable?]]></title><description><![CDATA[<p>I have the following:</p>
<p>class ChatRoom extends Room {</p>
<p>constructor () {<br />
super();</p>
<pre><code>this.setState({
  players: {},
  messages: [],
  roomname: []
});
</code></pre>
<p>}</p>
<p>In onJoin(client)...</p>
<p>//it works if I do this, I can retrieve the string in Unity.<br />
this.state.roomname.push ('a room passed as string');</p>
<p>var roomname = {<br />
roomName : 'a room passed as string'<br />
}</p>
<p>//it doesn't work if I do this, I get a '1' as the result when i try to read the object.<br />
this.state.roomname.push (roomname);</p>
<p>How do I push a variable?<br />
I'm thinking like in <a href="http://socket.io" rel="nofollow">socket.io</a> . I can send currentUser, in Unity I use  a Json deserialiser to read the contents.</p>
<pre><code>var currentUser = {
		msg:data.msg,
		id:id,
		position:data.position,
	}
socket.emit('move', currentUser);
</code></pre>
<p>Can I do something similar using this.state.roomname.push(currentUser) ?</p>
]]></description><link>http://discuss.colyseus.io/topic/10/how-to-push-a-variable</link><generator>RSS for Node</generator><lastBuildDate>Tue, 09 Jun 2026 18:05:15 GMT</lastBuildDate><atom:link href="http://discuss.colyseus.io/topic/10.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 30 Oct 2017 16:21:07 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to push a variable? on Mon, 30 Oct 2017 16:24:00 GMT]]></title><description><![CDATA[<p>I have the following:</p>
<p>class ChatRoom extends Room {</p>
<p>constructor () {<br />
super();</p>
<pre><code>this.setState({
  players: {},
  messages: [],
  roomname: []
});
</code></pre>
<p>}</p>
<p>In onJoin(client)...</p>
<p>//it works if I do this, I can retrieve the string in Unity.<br />
this.state.roomname.push ('a room passed as string');</p>
<p>var roomname = {<br />
roomName : 'a room passed as string'<br />
}</p>
<p>//it doesn't work if I do this, I get a '1' as the result when i try to read the object.<br />
this.state.roomname.push (roomname);</p>
<p>How do I push a variable?<br />
I'm thinking like in <a href="http://socket.io" rel="nofollow">socket.io</a> . I can send currentUser, in Unity I use  a Json deserialiser to read the contents.</p>
<pre><code>var currentUser = {
		msg:data.msg,
		id:id,
		position:data.position,
	}
socket.emit('move', currentUser);
</code></pre>
<p>Can I do something similar using this.state.roomname.push(currentUser) ?</p>
]]></description><link>http://discuss.colyseus.io/post/12</link><guid isPermaLink="true">http://discuss.colyseus.io/post/12</guid><dc:creator><![CDATA[shophk]]></dc:creator><pubDate>Mon, 30 Oct 2017 16:24:00 GMT</pubDate></item><item><title><![CDATA[Reply to How to push a variable? on Invalid Date]]></title><description><![CDATA[<p>My solution to this is using JSON.stringify to parse the variable into a string. I'm hoping there is a better solution.</p>
<p>var roomname = {<br />
roomName : 'a room passed as string'<br />
}<br />
var text = JSON.stringify (roomname);<br />
console.log(&quot;stringify text: &quot; + text);</p>
<pre><code>   this.state.roomname.push (text);</code></pre>
]]></description><link>http://discuss.colyseus.io/post/13</link><guid isPermaLink="true">http://discuss.colyseus.io/post/13</guid><dc:creator><![CDATA[shophk]]></dc:creator><pubDate>Invalid Date</pubDate></item></channel></rss>