Verb [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=68936 Parallel functions <p> <table><tr><td> <a href="/bbs/?pid=174466#p"> <img src="/bbs/thumbs/pico8_parallel-0.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=174466#p"> parallel</a><br><br> by <a href="/bbs/?uid=68936"> Verb</a> <br><br><br> <a href="/bbs/?pid=174466#p"> [Click to Play]</a> </td></tr></table> <br /> I've been playing Computercraft and decided to create a simplified version of its Parallel API for Pico-8. This code introduces two functions: <code>waitforany</code> and <code>waitforall</code>, which lets you run multiple functions in parallel using coroutines.</p> <p>Actually, the entered functions don't all run at the same time; functions will run in sequence and switch between themselves whenever they <code>yield()</code>. The above cart shows an example usage of both functions.</p> <h3>waitforany()</h3> <p>Takes functions as parameters, and runs each one in parallel.<br /> Returns the index of the first function that finishes.</p> <p>usage:<br /> <code>waitforany(func1, func2, ...)</code></p> <p>code:</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>function waitforany(...) colist = {...} for i=1,#colist do colist[i] = cocreate(colist[i]) end while true do for i=1,#colist do assert(coresume(colist[i])) if costatus(colist[i])==&quot;dead&quot; then return i end end end end</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <h3>waitforall()</h3> <p>Takes functions as parameters, and runs each one in parallel.<br /> Returns when all functions have finished running.</p> <p>usage:<br /> <code>waitforall(func1, func2, ...)</code></p> <p>code:</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>function waitforall(...) colist = {...} for i=1,#colist do colist[i] = cocreate(colist[i]) end local i=0 while true do if (#colist == 0) return i+=1 if (i&gt;#colist) i=1 assert(coresume(colist[i])) if costatus(colist[i])==&quot;dead&quot; then deli(colist,i) i-=1 end end end</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <h2>WARNING</h2> <p>Be sure to pass in the names of functions you want to run in parallel, and <strong>not</strong> the result of the functions.<br /> <code>waitforany(func1, func2)</code> ✅ right<br /> <code>waitforany(func1(), func2())</code> ❌ wrong</p> https://www.lexaloffle.com/bbs/?tid=151702 https://www.lexaloffle.com/bbs/?tid=151702 Tue, 23 Sep 2025 23:30:16 UTC Peg Twister <p> <table><tr><td> <a href="/bbs/?pid=172691#p"> <img src="/bbs/thumbs/pico8_peg_twister-0.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=172691#p"> Peg Twister</a><br><br> by <a href="/bbs/?uid=68936"> Verb</a> <br><br><br> <a href="/bbs/?pid=172691#p"> [Click to Play]</a> </td></tr></table> <br /> Also known as Insanity or Madness. Peg Twister is a simple board game where a single player moves red and blue pegs from opposite ends of the board to the other side, switching their positions. The player can only move forward one space at a time or jump over another peg.</p> https://www.lexaloffle.com/bbs/?tid=151150 https://www.lexaloffle.com/bbs/?tid=151150 Sun, 24 Aug 2025 01:18:19 UTC memset and memcpy <p> <table><tr><td> <a href="/bbs/?pid=170764#p"> <img src="/bbs/thumbs/pico8_memset_memcpy-0.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=170764#p"> memset_memcpy</a><br><br> by <a href="/bbs/?uid=68936"> Verb</a> <br><br><br> <a href="/bbs/?pid=170764#p"> [Click to Play]</a> </td></tr></table> </p> <p>Messing around with memset and memcpy functions.</p> https://www.lexaloffle.com/bbs/?tid=150448 https://www.lexaloffle.com/bbs/?tid=150448 Mon, 21 Jul 2025 19:47:59 UTC