Miez [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=61029 Pico-8 Feature Request: use logical statements in calculations <p>OK, I know we can use ternary conditions in variable assignments. But - as far as I can tell - they can't be used in calculations. Having logical statements be used as a value operator in a calculation can be used in many circumstances, would be readable and possibly pretty token efficient.</p> <p>How might this look?</p> <p>(a &gt; b) would result in a 1 if true, 0 if false.</p> <p>something like &quot;pset(100+100*(a &gt; b), 200, 7)&quot; would prevent the use of a bunch of ternary assignments, local variables or if statements.</p> <p>So what do you think? Useful? Doable? Worth it? </p> https://www.lexaloffle.com/bbs/?tid=50270 https://www.lexaloffle.com/bbs/?tid=50270 Fri, 18 Nov 2022 14:22:28 UTC Is there a way to pause _draw() ? <p>Probably a silly question, but I can't seem to work it out.</p> <p>I have a slow function - it takes more than 1/30 of second to execute but needs to be done in the _draw() function. This makes my code slow and unresponsive and it's clearly not the way to do it.</p> <p>So what I want to do is the following:</p> <ul> <li>run my slow function once in the _init() (drawing a bunch of stuff to the screen)</li> <li>capture the screen to extended memory</li> <li>in my _draw() function do repeated copies back to the screen</li> </ul> <p>This works ... BUT ... when I run my slow function it shows on the screen (briefly, during _init() ). Probably because it overruns the 1/30 second _draw update time. I would rather suspend draw updates during _init().</p> <p>So is there a way to suspend screen refreshing for a bit and then switch it back on?</p> https://www.lexaloffle.com/bbs/?tid=46548 https://www.lexaloffle.com/bbs/?tid=46548 Fri, 11 Feb 2022 22:39:30 UTC Infinite random &quot;word&quot; generator <p>The code below creates a random &quot;word&quot; that's 2 to 12 characters long. Some results are better than others and absolutely no guarantee it won't generate rude words (in whatever language you'd like to be offended in). This snippet might come in handy somewhere and can very easily be tweaked.<br /> Great for all your randomly generated NPC's, Legendary Weapons, Chthonic demons and faraway planet systems.</p> <p>Very loosely based on Jabbalaci's Python version (<a href="https://github.com/jabbalaci/Elite">https://github.com/jabbalaci/Elite</a>) of Ian Bell's txtelite.c script for Elite.</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>str_namefrags=split(&quot;AB,OU,AA,IT,ION,YL,IF,ON,ETO,AE,ERA,US,EON,ES,AR,UME,IN,AH,ER,AL,UR,AV,ET,IUS,IE,UJ,EY,YS,ON&quot;,&quot;SE,NYA,HY,SU,LO,NU,GA,LON,TH,NA,HO,LE,XA,DIA,GE,ZA,VAN,CE,HE,BI,SO,MA,DI,VE,RE,SEN,RA,TE,HI,NY,WEN,DO,QU,KI&quot;) function random_word() -- creates a random word -- words are anything from 2 to 12 characters long -- _len = length of the word in fragments local _len,_res,_hyphen,_c,_frag = 2+flr(rnd(3)),&quot;&quot;,0,0,&quot;&quot; for z=1,_len do _frag=str_namefrags[1+flr(rnd(#str_namefrags))] -- generate a random chance to do special stuff with the chosen fragment _c=flr(rnd(16)) if _c==0 then -- switch the first and last letter _res=_res..sub(_frag,-1,-1)..sub(_frag,1,1) elseif (_c==1 and _res!=&quot;&quot; and z&lt;_len and _hyphen==0) then -- if the string already contains some text, we're not at the -- last fragment and we've not done -- this before: add either a space, hyphen or apostrophe. local _mark = 1+flr(rnd(3)) _res=_res..sub(&quot; '-&quot;,_mark,_mark) _hyphen=1 elseif _c==2 then -- use only the first letter of the chosen fragment _res=_res..sub(_frag,1,1) elseif _c==3 then -- use only the last letter of the chosen fragment _res=_res..sub(_frag,-1,-1) else -- in all other cases: simply add the chosen fragment _res=_res.._frag end end if (#_res&lt;5 and flr(rnd(70))==0) then -- if the result is short and once in 70 times: -- add the result to itself with a space in between _res=_res..&quot; &quot;.._res end return _res end</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>A sample of the &quot;words&quot; it will generate:<br /> ETORAU<br /> VEAUSSEN<br /> NQU<br /> IFVANERA<br /> DIAIIUS<br /> GESEUJAH<br /> VANONA<br /> TEUJAVUJ<br /> CELOOUVE<br /> INNUE<br /> NYADIA<br /> RAUSY<br /> UJSU<br /> REZA<br /> SYIE<br /> ONEY<br /> ETUSEYR<br /> IUSYL<br /> ITSENHEDIA<br /> OUQREZA<br /> DOARAH<br /> ELE<br /> DI'AA<br /> AVHISU<br /> TIURQU<br /> US-DIUS<br /> LENUITWEN<br /> AEOUTHA<br /> UME UME<br /> KIETNYA<br /> EEAASU<br /> REUMEEY<br /> DIL<br /> ITARNYALO<br /> CEIFU<br /> HE-ALSU<br /> ABHIAA<br /> AVALAAV<br /> TELONHY</p> https://www.lexaloffle.com/bbs/?tid=46294 https://www.lexaloffle.com/bbs/?tid=46294 Mon, 24 Jan 2022 22:07:38 UTC Two decimal string from a number <p>Tiny function that takes a number (float or int) and returns a string with (maximum) two decimals. For instance:</p> <p>10 &gt; &quot;10&quot;<br /> 20.03 &gt; &quot;20.03&quot;<br /> 17.46134 &gt; &quot;17.46&quot;</p> <p>So not mathematically accurate, but useful under some circumstances...</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 twodecimal(_n) -- will accept a number (float or int) -- turn it into a string and return the string with two decimals local _v=split(tostring(_n),&quot;.&quot;) if #_v==1 then return _v[1] else return (_v[1]..&quot;.&quot;..sub(_v[2],1,2)) 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> https://www.lexaloffle.com/bbs/?tid=46172 https://www.lexaloffle.com/bbs/?tid=46172 Fri, 14 Jan 2022 21:48:37 UTC