<br><br><div><span class="gmail_quote">On 8/3/07, <b class="gmail_sendername">Martin Ahnelöv</b> &lt;<a href="mailto:operagasten@gmail.com">operagasten@gmail.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
&gt; loops, but wanted them to run &quot;side-by-side&quot;, but looping at different<br>&gt; speeds, how would you do it?<br>&gt;</blockquote><div><br>&nbsp;</div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Yes, you can do that. FYI, it&#39;s called threading in traditional<br>programming languages and is often a pain in the ass, but since chuck<br>isn&#39;t a traditional language it&#39;s called sporking and is as simple as
<br>running a chuck file.</blockquote><div><br>That&#39;s right!<br><br>&nbsp;</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>You can also do sporking in the code, but I haven&#39;t looked at that
<br>enough - it&#39;s in the help pages, though.</blockquote><div><br>That&#39;s also quite simple. You can run threads (we call them shreds) next to the main one. You define those as functions and you &quot;spork&quot; the function.
<br>=======================================<br>//let&#39;s define a function<br>fun void paralel()<br>{<br>while(true)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; //this will loop forever<br>&nbsp;&nbsp;&nbsp; &lt;&lt;&lt;&quot;beep&quot;&gt;&gt;&gt;;<br>&nbsp;&nbsp;&nbsp; second =&gt; now;
<br>&nbsp;&nbsp;&nbsp; }<br>}<br>&nbsp;</div><br>//let&#39;s try sporking it<br>spork ~ paralel();<br><br>//now we write the main loop that will run next to it<br>while(true)<br>{<br>//this will also loop forever<br>&lt;&lt;&lt;&quot;boop&quot;&gt;&gt;&gt;;
<br>.75::second =&gt; now;<br>}<br><br><br>//anything that you would write here will never get executed because the program will always be stuck in that last loop. you could still define functions here though.<br><br>-----------------------------
<br><br>See? not at all hard. You can run as many functions next to eachother as you like, they can all be different or they could all be the same. If they are all the same you only need to define it once and can spork it as many times as you&#39;d like (untill the cpu gives up! Notice that they can all run at different speeds if you&#39;d like, in my example above one loops in .75 seconds while the other takes a whole second so they will drift in and out of phase.
<br><br>Cheers,<br>Kas.<br></div>