<?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[&#x27;random&#x27; clock timing]]></title><description><![CDATA[<p>I'm trying to create some 'bot' players in my game (controlled server-side) that act at 'random' times.<br />
My concept was to fire a clock.setTimeout() with a random time, that calls the 'botActions' function, and at the end of that function calls itself again using another setTimeout with a different 'random' time.<br />
However, within the first this.clock.setTimeout, I can't seem to access this.clock.setTimeout... &quot;this&quot; is undefined...<br />
Scope issue, I assume...? Is there a more 'proper' way to accomplish this?<br />
Thanks!<br />
David</p>
<p><em>without random time</em></p>
<pre><code>botUpdate(data){
        console.log(&quot;bot clock tick:&quot;, data);
        this.clock.setTimeout(this.botUpdate, 1000, {botID : data.botID});
}
</code></pre>
<p>this.clock.setTimeout(this.botUpdate, 1000, {botID : data.botID});<br />
TypeError: Cannot read property 'setTimeout' of undefined</p>
]]></description><link>http://discuss.colyseus.io/topic/184/random-clock-timing</link><generator>RSS for Node</generator><lastBuildDate>Tue, 18 Aug 2026 08:30:56 GMT</lastBuildDate><atom:link href="http://discuss.colyseus.io/topic/184.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 19 Dec 2018 20:11:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to &#x27;random&#x27; clock timing on Invalid Date]]></title><description><![CDATA[<p>I'm trying to create some 'bot' players in my game (controlled server-side) that act at 'random' times.<br />
My concept was to fire a clock.setTimeout() with a random time, that calls the 'botActions' function, and at the end of that function calls itself again using another setTimeout with a different 'random' time.<br />
However, within the first this.clock.setTimeout, I can't seem to access this.clock.setTimeout... &quot;this&quot; is undefined...<br />
Scope issue, I assume...? Is there a more 'proper' way to accomplish this?<br />
Thanks!<br />
David</p>
<p><em>without random time</em></p>
<pre><code>botUpdate(data){
        console.log(&quot;bot clock tick:&quot;, data);
        this.clock.setTimeout(this.botUpdate, 1000, {botID : data.botID});
}
</code></pre>
<p>this.clock.setTimeout(this.botUpdate, 1000, {botID : data.botID});<br />
TypeError: Cannot read property 'setTimeout' of undefined</p>
]]></description><link>http://discuss.colyseus.io/post/601</link><guid isPermaLink="true">http://discuss.colyseus.io/post/601</guid><dc:creator><![CDATA[davidhoare]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to &#x27;random&#x27; clock timing on Thu, 20 Dec 2018 20:00:43 GMT]]></title><description><![CDATA[<p>Hi <a class="plugin-mentions-user plugin-mentions-a" href="http://discuss.colyseus.io/uid/261">@davidhoare</a>, welcome!</p>
<p>This is the classical mistake regarding the <code>this</code> scope in JavaScript, no worries, everyone's been there! <a href="https://discuss.colyseus.io/topic/162/syncing-part-of-state-design-paradigm/2" rel="nofollow">Here's a related discussion in the forum</a>.</p>
<p>To preserve the <code>this</code> scope in JavaScript, you can either use <code>this.botUpdate.bind(this)</code>, or create an arrow function.</p>
<p><strong>Examples:</strong></p>
<pre><code>// using Function.prototype.bind
this.clock.setTimeout(this.botUpdate.bind(this), 1000, {botID : data.botID});
</code></pre>
<pre><code>// using arrow functions (block)
this.clock.setTimeout(() =&gt; {
    this.botUpdate();
}, 1000, {botID : data.botID});

// using arrow functions (single line; shorthand)
this.clock.setTimeout(() =&gt; this.botUpdate(), 1000, {botID : data.botID});
</code></pre>
<p>Hope this helps! Happy holidays!</p>
]]></description><link>http://discuss.colyseus.io/post/602</link><guid isPermaLink="true">http://discuss.colyseus.io/post/602</guid><dc:creator><![CDATA[endel]]></dc:creator><pubDate>Thu, 20 Dec 2018 20:00:43 GMT</pubDate></item></channel></rss>