<?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[SessionId is undefined when leaving and joining again.]]></title><description><![CDATA[<p>Hi - i've been experimenting with Colyseus for a while, but when I have three tabs open, and close one, and then reopen it and rejoin, the other tabs are claiming that the SessionId is undefined. Is there something wrong with my code? I tried setting a property on the state called uuid which is basically the sessionid, but it still didn't work. Players is an empty array.</p>
<p>Add player function (im using <a href="http://paperjs.org/" rel="nofollow">paperjs</a>):</p>
<pre><code class="language-javascript">function addPlayer(nickname,position,color,uid) {
    console.log(&quot;player added as&quot;,uid)
    var circle = new Path.Circle(position,20)
    circle.fillColor = color
    console.log(nickname + &quot; has joined the server&quot;)
    players[uid] = {
        circle: circle,
        nickname: nickname
    }
    console.log(players[uid])
} 
</code></pre>
<p>State watching function thing:</p>
<pre><code class="language-javascript">    addlog(&quot;joined succesfully!&quot;)
    console.log(room)
    room.onMessage(function(msg) {
        addlog(msg)
    })
    room.state.players.onChange = function(plr,sesh) {
        // it exists and it's not us
        if(players[plr.uuid] &amp;&amp; plr.uuid != room.sessionId &amp;&amp; plr.uuid) {
            // players[sesh].circle.position.x = plr.x
            // players[sesh].circle.position.y = plr.y
            var thepoint = new Point(plr.x,plr.y)
            var tween = players[plr.uuid].circle.tweenTo(
                { position: thepoint},
                { duration: 100, start: false, easing: &quot;linear&quot;}
            );
            tween.start();
            console.log(&quot;started tween for&quot;,players[plr.uuid].nickname)
        }else{
            console.log(&quot;errorrorr&quot;)
            console.log(players[plr.uuid], room.sessionId, sesh)
        }
    }
    room.state.players.onAdd = function(plr,session) {
        if(plr.uuid == undefined) {
            alert(&quot;sessionid undefined&quot;)
        }
        console.log(&quot;user is being added!&quot;)
        if(plr.uuid != room.sessionId) {
            addPlayer(plr.nickname,new Point(plr.x,plr.y),plr.color,plr.uuid)
            console.log(plr,plr.uuid)
            addlog(players[plr.uuid].nickname + &quot; joined!&quot;)
        }
    }
    room.state.players.onRemove = function(plr,session) {
        console.log(&quot;user is being removed!&quot;)
        if(players[plr.uuid] &amp;&amp; plr.uuid) {
            players[plr.uuid].circle.remove()
            addlog(players[plr.uuid].nickname + &quot; left.&quot;)
            players[plr.uuid] = undefined
        }
    }
</code></pre>
<p>I'm really confused about why this is happening... any ideas?</p>
]]></description><link>http://discuss.colyseus.io/topic/330/sessionid-is-undefined-when-leaving-and-joining-again</link><generator>RSS for Node</generator><lastBuildDate>Sun, 19 Jul 2026 15:57:47 GMT</lastBuildDate><atom:link href="http://discuss.colyseus.io/topic/330.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 06 Mar 2020 15:05:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to SessionId is undefined when leaving and joining again. on Invalid Date]]></title><description><![CDATA[<p>Hi - i've been experimenting with Colyseus for a while, but when I have three tabs open, and close one, and then reopen it and rejoin, the other tabs are claiming that the SessionId is undefined. Is there something wrong with my code? I tried setting a property on the state called uuid which is basically the sessionid, but it still didn't work. Players is an empty array.</p>
<p>Add player function (im using <a href="http://paperjs.org/" rel="nofollow">paperjs</a>):</p>
<pre><code class="language-javascript">function addPlayer(nickname,position,color,uid) {
    console.log(&quot;player added as&quot;,uid)
    var circle = new Path.Circle(position,20)
    circle.fillColor = color
    console.log(nickname + &quot; has joined the server&quot;)
    players[uid] = {
        circle: circle,
        nickname: nickname
    }
    console.log(players[uid])
} 
</code></pre>
<p>State watching function thing:</p>
<pre><code class="language-javascript">    addlog(&quot;joined succesfully!&quot;)
    console.log(room)
    room.onMessage(function(msg) {
        addlog(msg)
    })
    room.state.players.onChange = function(plr,sesh) {
        // it exists and it's not us
        if(players[plr.uuid] &amp;&amp; plr.uuid != room.sessionId &amp;&amp; plr.uuid) {
            // players[sesh].circle.position.x = plr.x
            // players[sesh].circle.position.y = plr.y
            var thepoint = new Point(plr.x,plr.y)
            var tween = players[plr.uuid].circle.tweenTo(
                { position: thepoint},
                { duration: 100, start: false, easing: &quot;linear&quot;}
            );
            tween.start();
            console.log(&quot;started tween for&quot;,players[plr.uuid].nickname)
        }else{
            console.log(&quot;errorrorr&quot;)
            console.log(players[plr.uuid], room.sessionId, sesh)
        }
    }
    room.state.players.onAdd = function(plr,session) {
        if(plr.uuid == undefined) {
            alert(&quot;sessionid undefined&quot;)
        }
        console.log(&quot;user is being added!&quot;)
        if(plr.uuid != room.sessionId) {
            addPlayer(plr.nickname,new Point(plr.x,plr.y),plr.color,plr.uuid)
            console.log(plr,plr.uuid)
            addlog(players[plr.uuid].nickname + &quot; joined!&quot;)
        }
    }
    room.state.players.onRemove = function(plr,session) {
        console.log(&quot;user is being removed!&quot;)
        if(players[plr.uuid] &amp;&amp; plr.uuid) {
            players[plr.uuid].circle.remove()
            addlog(players[plr.uuid].nickname + &quot; left.&quot;)
            players[plr.uuid] = undefined
        }
    }
</code></pre>
<p>I'm really confused about why this is happening... any ideas?</p>
]]></description><link>http://discuss.colyseus.io/post/1085</link><guid isPermaLink="true">http://discuss.colyseus.io/post/1085</guid><dc:creator><![CDATA[MoonBarc]]></dc:creator><pubDate>Invalid Date</pubDate></item></channel></rss>