Time delay in Javascript
<p>Function PS.Tick() is called every 100 milliseconds and its job is to call AI function of NPCs so they can move:</p>

<pre><code>PS.Tick = function ()
{
"use strict";
for (NPCid = 0; NPCid &lt; NPCnumber; NPCid++)
{
    NPCAI(NPCid);
};
}; 
</code></pre>

<p>But I want the NPCs to not move simultaneously every 100 millisecond, but do it at their own frequency, so I tried this code:</p>

<pre><code>PS.Tick = function ()
{
"use strict";
for (NPCid = 0; NPCid &lt; NPCnumber; NPCid++)
{
    var timeout = 0;
    timeout = PS.Random (1000);
    setTimeout("NPCAI(NPCid)",timeout);
};
};
</code></pre>

<p>Now, they don't move at all. Why? How do I make them move at different time intervals?</p>
