Felice [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=12874 Suggestion: &quot;backups&quot; command <p>Yo <a href="https://www.lexaloffle.com/bbs/?uid=1"> @zep</a>,</p> <p>On discord and here on the BBS, we get a lot of people who basically need to get to the auto-backup of a cart they've lost somehow. It'd spare a lot of time writing blurbs like <a href="https://www.lexaloffle.com/bbs/?pid=95617#p">this</a> if people could simply type &quot;backups&quot; and have it work like the &quot;folder&quot; command except it drops them in the 'backups' folder instead of 'carts'.</p> https://www.lexaloffle.com/bbs/?tid=44075 https://www.lexaloffle.com/bbs/?tid=44075 Tue, 03 Aug 2021 16:39:43 UTC API isn't quite consistent <p>In all but one case I can think of, PICO-8 specifies screen rectangles as X1,Y1-X2,Y2 (inclusive).</p> <p>The case where it doesn't is <strong>clip(x,y,w,h)</strong>.</p> <p>This has always bugged me. But worse, I noticed recently that the virtual hardware registers for the clip rect are actually set up like the other API calls: X1,Y1-X2,Y2 (inclusive), which means the API is actually translating between the paradigms.</p> <p>Now I realize <strong>clip()</strong> can't suddenly change to work the other way, but...</p> <p>What if we had a new command next to it called <strong>clp(x1,y1,x2,y2)</strong> that worked the same as everything else, worked like the virtual hardware, returned the same values you'd get by peeking the virtual hardware registers, etc., and simply marked <strong>clip()</strong> as deprecated, much like <strong>mapdraw()</strong> is deprecated?</p> <p>It would hardly be the only abbreviated API call, e.g. <strong>sgn()</strong>.</p> <p>What do you think, <a href="https://www.lexaloffle.com/bbs/?uid=1"> @zep</a>?</p> https://www.lexaloffle.com/bbs/?tid=43962 https://www.lexaloffle.com/bbs/?tid=43962 Tue, 27 Jul 2021 09:18:08 UTC tostr() can only do decimal and hex <p>Right now, <strong>tostr(n)</strong> converts to decimal, and <strong>tostr(n,anything_except_nil_or_false)</strong> converts to hex.</p> <p>Could it use the optional second arg as a base if it's a number? e.g.</p> <div> <div style="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>&gt;?tostr(255) 255 &gt;?tostr(255,false) 255 &gt;?tostr(255,true) 0x00ff.0000 &gt;?tostr(255,16) 0x00ff.0000 &gt;?tostr(255,10) 255 &gt;?tostr(255,2) 0b0000000011111111.0000000000000000</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>For the sake of simplicity, you could limit it to the bases the parser can read. I think that's just decimal, hex, and binary.</p> https://www.lexaloffle.com/bbs/?tid=43845 https://www.lexaloffle.com/bbs/?tid=43845 Fri, 16 Jul 2021 14:06:27 UTC Dev tools <p><em>&quot;Are you there <a href="https://www.lexaloffle.com/bbs/?uid=1"> @zep</a>? It's me again, <del>Margaret</del> Felice.&quot;</em></p> <p>I was thinking about how the option to show additional screens could open up the ability to write <em>on-target</em> dev tools to complement the existing IDE, and yet we're not really seeing any of that (yet).</p> <p>I don't think it's a big deal that these additional screens are officially unsupported and you have to alter the pico8.exe command line to use them at all, because only a dev needs dev tools, and devs know how to alter command lines. I don't think that's why.</p> <p>I think the problem with dev tools and debug libraries comes in the form of the token limit.</p> <p>Any and all dev tools are going to take up tokens, and once you go past 8192 tokens, your app <em>can't even launch.</em> So someone with a nearly-finished app that's utilizing most or all of the allowed tokens is going to be absolutely unable to use any form of dev tool, debugging library, or even just <strong>print()</strong> debugging.</p> <p>So...</p> <p><strong>Would it be possible to add a <em>command-line</em> option to increase the limit from 8K to, let's say, 32K tokens?</strong></p> <p>e.g. <strong>pico8.exe -dev_mode</strong></p> <p>That's similar to the 1:4 retail-vs-devkit RAM ratio on a PS2 devkit, for instance: 32MB vs 128MB. We had that extra RAM to hold debug libs, extra sanity-checking code, trace logs, etc., and it was absolutely <em>invaluable.</em></p> <p>And, most notably, this would <em>only</em> work when run from a proper <strong>pico8.exe</strong> with a command-line option set, meaning it is NOT supported under normal conditions and will NOT work in an exported/.png app, maintaining PICO-8's cozy limitations under normal circumstances.</p> <p>Oh, and note that you should also increase the Lua heap to 8MB in this mode, btw. Or more. More code means more data.</p> <hr /> <p>Afterthought: This also might encourage people to write stuff that will, in turn, give you ideas to improve PICO-8, Voxatron, or whatever comes after. In fact, the reason why I'm posting about this is that someone on the Discord mentioned that some of the Respriter ideas may have worked their way back into PICO-8. Synergy is food for the dev's soul!</p> https://www.lexaloffle.com/bbs/?tid=43341 https://www.lexaloffle.com/bbs/?tid=43341 Mon, 14 Jun 2021 21:46:05 UTC BBS Previews don't match forum posts <p>I just discovered there's &quot;&gt; ...&quot; quote block feature.</p> <p>Except there isn't...?</p> <p>If I do this:</p> <div> <div style="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>this is my introduction &gt; this is my quote this is my response</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>I get this in the preview:</p> <img style="" border=0 src="/media/12874/bbsquote.png" alt="" /> <p>But when I click <strong>[Publish]</strong> it comes out like this:</p> <img style="" border=0 src="/media/12874/bbsquote2.png" alt="" /> <p>Also, if this feature is intended to work, it should be in the <strong>[Formatting Help]</strong> helpbox.</p> https://www.lexaloffle.com/bbs/?tid=43176 https://www.lexaloffle.com/bbs/?tid=43176 Thu, 03 Jun 2021 06:17:26 UTC Missing BBS Category <p>Hey <a href="https://www.lexaloffle.com/bbs/?uid=1"> @zep</a>,</p> <p>There are a lot of people who come here and learn to code by modding existing carts, and personally I think iterating on someone else's project is a fantastic way to learn stuff (I do it too), so I'd never want to discourage it, but sometimes it floods the BBS too, especially when someone does a workshop or class where everyone does it.</p> <p>Could we get a <strong>Mods</strong> category under <strong>Cartridges</strong>?</p> <img style="" border=0 src="/media/12874/mods_cat.png" alt="" /> <p>That also might let you curate that kind of cartridge a little better, since a lot of them are only slightly different from the original, or indeed might not even work properly, and don't really belong in Splore, even though it's useful for junior programmers to share their work with each other here on the BBS and bounce ideas back and forth and so on.</p> https://www.lexaloffle.com/bbs/?tid=42946 https://www.lexaloffle.com/bbs/?tid=42946 Wed, 19 May 2021 18:23:06 UTC Another += pre-parser bug <p>Hey <a href="https://www.lexaloffle.com/bbs/?uid=1"> @zep</a>,</p> <p>I'm not sure if this is related to the last <strong>+=</strong> parser bug. It doesn't seem to be, but if it is, it's possible you already fixed it in your dev version.</p> <p>Having a tab as whitespace in this construct:</p> <div> <div style="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>t={1} t[1] +=1 -- (with visible whitespace) t={1} t[1]⟼+=1</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>Produces an &quot;unexpected symbol near +&quot; error.</p> <p>I copied the &quot;see what the pre-parser does&quot; trick to clipboard:</p> <div> <div style="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>printh([=[t[1] +=1]=], &quot;@clip&quot;)</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>And got this when I pasted it back into an editor</p> <div> <div style="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>t[1 ] = + (1) -- (with visible whitespace) t[1&middot;]⟼&middot;=&middot;⟼&middot;+&middot;(1)&middot;&middot;</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>Note that it only seems to do this if the left value is a table deref. Mind you, other complex lvalue patterns might also trigger it.</p> <p>Maybe your regex needs some &quot;\s*&quot; patterns where it currently only has &quot; *&quot;?</p> <p>I'll assume this is enough for you to go on. :)</p> <hr /> <p>...oh, and one tiny, itty-bitty, almost-not-worth-mentioning afterthought, since you're mucking with that code...</p> <p>It'd be <em>awful cool</em> if this worked:</p> <div> <div style="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>x,y += 64,64</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>just sayin' ;)</p> https://www.lexaloffle.com/bbs/?tid=42880 https://www.lexaloffle.com/bbs/?tid=42880 Fri, 14 May 2021 02:21:22 UTC Misfeature: 5512.5Hz audio should be crunchy, but not THIS crunchy <p>Hey <a href="https://www.lexaloffle.com/bbs/?uid=1"> @zep</a>,</p> <p>I've been messing around with software synth via the PCM trick and I feel like there's sort of a fundamental problem that's detracting a lot from the quality of what comes out the back end, needlessly so, not to mention making it uncomfortable to the listener's ear.</p> <p>As far as I can tell, you're feeding the 5512.5Hz signal into the audio version of a &quot;nearest neighbor&quot; sampler to upsample it to the host OS' audio hardware sample rate, which is typically gonna be either 44100Hz or 48000Hz. That means repeating the sample values as many times as necessary to fill the gaps. In this case it'd repeat the same value around 8 times. This of course produces stairsteps on the 44100Hz+ &quot;curve&quot;.</p> <p>The issue with that is that modern audio hardware has really good fidelity and it's going to reproduce those sharp stairsteps very faithfully, effectively overlaying a constant 5512.5Hz triangle wave on the original wave that pulsates its amplitude based on how big the deltas between samples are in the original wave.</p> <p>Like, if the original wave was a 262Hz middle-C sine wave tone, you'd get a 5512.5Hz buzz overlaid that gets strongest each time the wave crosses 0, where the rate of change is maximal. It crosses 0 twice per cycle, so you're getting an audible crackling buzz at 524Hz.</p> <p>That's not what would have happened on old analog audio output circuitry. There would be ramping time between levels, some sort of acceleration, deceleration, and maybe overshoot too, as the line settled at its new level. Basically the audio version of an LCD pixel's &quot;response time&quot; or &quot;gray-to-gray time&quot;. The overlaid triangle wave would be closer to a sine wave, more of a tone than a buzz, still present and still distorting the intended wave a bit, but much less harsh to the ear.</p> <p>I dunno what options you have to change the upsampling. If you're doing it by hand, your options are open, but if you're relying on hardware, you might need to experiment. You probably don't want to change it over to using full interpolation, because that'll make it hard for people to do deliberate buzzing.</p> <p>If it were me, I'd try doing a manual nearest-neighbor upsample to 22100Hz (edit: or maybe just 11050Hz) to retain the low-resolution stairsteps you'd expect the low clock rates to produce on retro hardware, but I'd let the host OS/hardware do interpolation to upsample it the rest of the way to the true output rate of 44100Hz or 48000Hz, which will simulate the ramping up/down time. This'd take the edge off, for the sake of the listener's ear.</p> https://www.lexaloffle.com/bbs/?tid=42811 https://www.lexaloffle.com/bbs/?tid=42811 Sat, 08 May 2021 00:20:27 UTC Bug? Backspace char is inconsistent <p>I've discovered that printing the &quot;\b&quot; character (8) moves the cursor back based on the width of the most recent glyph that was printed.</p> <p>So, <a href="https://www.lexaloffle.com/bbs/?uid=1"> @zep</a>, I can understand where your mind was going with this, because you wanted it to be possible to back up over something like a kana character or a PICO-8 emoji with a single backspace. That does make sense.</p> <p>However, I think unless you're going to keep a long history of what was printed before that, and where the cursor was for each glyph, it's going to cause problems, because right now it's only guaranteed to work for backspacing over <em>one</em> character, not more.</p> <p>For instance, if I <strong>print(&quot;abしd\b\bcd&quot;)</strong>, it doesn't put &quot;cd&quot; in the right place, as shown below, where I highlight the overprinting in the second print by changing the foreground color to orange:</p> <img style="" border=0 src="/media/12874/abshid.png" alt="" /> <p>Point being, you're trying to be helpful to the user by remembering the width of the last glyph, but it's not helpful to the next user who wants to back up over two glyphs. It's not a game I think you can play to win. I think it'd be better just to set backspace.dx to a constant for the font, be it oem or custom. </p> <p>You should probably just set backspace to be literally a backwards space. Let the user deal with double-wide or narrow glyphs if they need to&mdash;they know what they're printing, after all.</p> <p>(Another option would be to give us a command code to set the backspace size, e.g. &quot;\^&lt;4&quot;, and default it to 4 or whatever is appropriate for a custom font. Leaving it in our hands solves all the problems, honestly.)</p> https://www.lexaloffle.com/bbs/?tid=42398 https://www.lexaloffle.com/bbs/?tid=42398 Sat, 10 Apr 2021 11:58:41 UTC Saving to wrong filename <p>I noticed this while looking at load/save behavior for my QoL idea.</p> <p>You can load a file that has no extension, because <strong>load</strong> will try the raw filename first without adding an extension.</p> <p>However, when you <strong>save</strong> that file, it will automatically add &quot;.p8&quot; to the name, possibly overwriting an existing file while not overwriting the file you actually loaded.</p> <p>Probably not going to happen much in practice, but potentially disastrous when it does happen.</p> <img style="" border=0 src="/media/12874/disaster.png" alt="" /> https://www.lexaloffle.com/bbs/?tid=42311 https://www.lexaloffle.com/bbs/?tid=42311 Mon, 05 Apr 2021 09:07:36 UTC QoL: auto-extend '#include' filenames like 'load' does <p>At the command prompt, if you try to <strong>load</strong> a filename with no extension:</p> <div> <div style="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>load somefile</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>It'll try these in order:</p> <div> <div style="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>somefile somefile.p8 somefile.p8.png</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>It'd be nice if <strong>#include</strong> worked the same way.</p> <p>e.g. with <strong>vector.p8</strong> in the same folder:</p> <div> <div style="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>#include vector</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>I think simply re-using the logic from <strong>load</strong> would work, because it behaves exactly the way I'm suggesting.</p> <p>As for Lua files, it's probably best if the <strong>.lua</strong> extension has to be typed out explicitly, because you're essentially leaving the sphere of PICO-8 by using a raw lua file and it makes sense that PICO-8's name abbreviation would not apply. Plus this is the same behavior <strong>load</strong> already uses, so minimum effort required. ;)</p> https://www.lexaloffle.com/bbs/?tid=42309 https://www.lexaloffle.com/bbs/?tid=42309 Mon, 05 Apr 2021 08:54:22 UTC Use select(bool,tval,fval) to select one of two values? <p><a href="https://www.lexaloffle.com/bbs/?uid=1"> @zep</a></p> <p>It'd be really intuitive and helpful if the <strong>select()</strong> function also detected a boolean value for the first argument, and returned the first arg if true and the second arg if not.</p> <p>A lot of us write our own ternary function that does this anyway, because it can work around some gotchas with the <strong>cond and tval or fval</strong> structure, so this would obviate the need for it while extending the existing API in a very intuitive way.</p> <p>e.g.</p> <div> <div style="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>-- this works as you'd expect a C/C++/JS-style &quot;cond? nil : that&quot; ternary op to work this = select( cond, nil, that ) -- this doesn't, it returns 'that' regardless of 'cond' this = cond and nil or that</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>Plus I think this would evaluate faster on the host.</p> <p>Should probably also treat <strong>nil</strong> as <strong>false</strong>, btw, for maximal usefulness and congruence with Lua's concept of conditions.</p> https://www.lexaloffle.com/bbs/?tid=42163 https://www.lexaloffle.com/bbs/?tid=42163 Thu, 25 Mar 2021 15:46:16 UTC Bug: can't disable BG-fill text? <p>I can't see a way to disable the new &quot;\#n&quot; background-fill mode once it's been enabled. I've tried &quot;0&quot; for color 0, &quot;G&quot; for color 16, and &quot;W&quot; for color 32, but they just set the BG to black, and all other &quot;0-Z&quot; just repeat the palette. I've tried supplying a &quot;-&quot; for the color instead, I've tried repeating the &quot;\#&quot; code or just &quot;#&quot;, I've tried various other symbols and the puny letters, and anything not in &quot;0..Z&quot; just sets it to black.</p> <p>Is this a missing feature or is there supposed to be a way to do it? The manual says nothing of turning it off. Right now I have to start another print() to get back to no-BG mode and that seems... unintended?</p> <p>I feel like it ought to be &quot;\#-&quot;, based on the convention with the &quot;\^&quot; commands. Alternatively, &quot;G&quot; (or anything through &quot;V&quot;) would technically make sense if you just consider bit #4 of the color to be a &quot;transparency&quot; bit.</p> <p>Edit: Just to be clear, I mean within the same print string. You can print again and the flag will be cleared, but for the sake of tokens, I'd like to do it within the same string.</p> https://www.lexaloffle.com/bbs/?tid=42068 https://www.lexaloffle.com/bbs/?tid=42068 Thu, 18 Mar 2021 19:33:17 UTC Bug with control codes <p>Before the most recent update, you could print anything below <strong>chr(32)</strong> and get an actual glyph in the output, aside from the obvious exceptions like \n and \t. For characters below <strong>chr(16)</strong> this is no longer possible, aside from <strong>chr(5)</strong>, which I suspect is an oversight. In fact, that oversight is the &quot;bug&quot; that brought me here.</p> <p>The thing is, this is a waste of 16 glyphs in the character set, and potentially up to 32 in the future if you add more control codes.</p> <p>Can we get some kind of &quot;raw&quot; printing mode, where control character behaviors are completely ignored and their glyphs are simply printed?</p> <p>Maybe turn the two oem/custom font selector characters into a single oem/custom toggle to free up <strong>chr(15)</strong>, and use that as a raw-mode toggle, as in this pseudocode, where raw mode allows everything to be printed except the toggle itself, unless it is repeated:</p> <div> <div style="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>fn print(s, ...) raw = false just_toggled_raw = false for each char c in s if c == raw_toggle then if just_toggled_raw then // escape the toggle draw_glyph( c ) // remember if it was a lone toggle, forget if it was doubled to escape just_toggled_raw = not just_toggled_raw raw = not raw else just_toggled_raw = false if raw then draw_glyph( c ) else ...insert existing print code here...</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>Apologies if I've missed some existing way to do this.</p> https://www.lexaloffle.com/bbs/?tid=42049 https://www.lexaloffle.com/bbs/?tid=42049 Wed, 17 Mar 2021 11:52:49 UTC Strange choice in abs() edge case <p>This is to do with the so-called &quot;outpost&quot; value, or the two's-complement wrap point, which in PICO-8's number system is 0x8000, or when printed as signed decimal, -32768.</p> <p>Like the origin, 0x0000, it's technically not really signed, or maybe it's better to say it covers both signs simultaneously. Conventions assign the origin to the positive side, and the outpost to the negative side, but that's just a pragmatic choice for numbers that unavoidably behave strangely due to the encoding. The origin and the outpost are complementary values in this way.</p> <p>(This is why 0 == -0 and -(-32768) == -32768 with a 16-bit signed integer, by the way.)</p> <p>That being said, this is what I currently get for the outpost value:</p> <div> <div style="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>&gt; print(tostr(abs(-32768),true)) 0x0000.0001</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>Obviously, there's no &quot;good&quot; result when we can't represent +32768 with a signed 16-bit integer.</p> <p>But this result is just plain wrong in every way, because it has no connection to anything someone might <em>expect</em> to get as an alternative to the impossible correct result. It's not equal to -(-32768), it's not close to +32768, and it's not even exactly 0.</p> <ul> <li> <p>Technically, I think it should return 0x8000 a.k.a. -32768, just like -0x8000 a.k.a. -(-32768) does. This way, -abs(-32768) returns what it should, which matters in some cases. This is basically in keeping with the usual properties of the outpost value.</p> </li> <li> <p>An <em>option,</em> albeit one I don't approve of because it's not symmetrical if you try to undo it, is to return 0x7fff.ffff, or not <em>quite</em> 32768. This would make the one rare edge case where someone was pushing numeric limits on PICO-8 work <em>almost</em> correctly, but honestly I think any calculation with a number this size is still going to fail and really ought to be done differently, so it's better if it fails obviously. Holding the hand of a new programmer in a rare edge case isn't worth breaking the behavior a seasoned one would <em>expect</em> in the same edge case.</p> </li> <li> <p>Another option would be to return exactly 0, rather than slightly more than 0, to make the &quot;bad input&quot; situation more clear to the dev so they can fix it, because a dev trying to work with abs(0x8000) is not going to have a good day anyway and they should probably find out as soon as possible. This feels like a sketchy idea, though. And it brings us to the final option....</p> </li> <li>The most draconian option would be to trigger a runtime error, since it's literally impossible to represent the result. I'm not sure how I feel about this. It'd definitely help devs find problems with their math, but there's always the chance it <em>won't</em> happen to the dev during development and <em>will</em> happen to the user in the wild, which is not okay. A glitch in the wild is bad but tolerable, a crash isn't.</li> </ul> <p>Anyway, as you can probably tell, I think abs(0x8000) should just return 0x8000, which means in layspeak that abs(-32768) returns -32768. That may (and should) feel nonsensical to a junior programmer, but everyone needs to learn the weird rules about the outpost value eventually anyway, so I think it's the real pragmatic choice.</p> <p>/me steps off of soapbox</p> https://www.lexaloffle.com/bbs/?tid=42031 https://www.lexaloffle.com/bbs/?tid=42031 Tue, 16 Mar 2021 13:39:11 UTC Forum @ bug <p>I noticed in <a href="https://www.lexaloffle.com/bbs/?pid=84005#p">this post</a> that @choo-t doesn't turn into a user link.</p> <p>Must be the hyphen?</p> https://www.lexaloffle.com/bbs/?tid=40301 https://www.lexaloffle.com/bbs/?tid=40301 Sun, 08 Nov 2020 20:59:31 UTC Regression: pack().n is broken again <p>I'm surprised I haven't noticed this before.</p> <p>I'm not sure if this is a regression in 0.2.1b or if it got outright broken, but <a href="https://www.lexaloffle.com/bbs/?uid=1"> @zep</a>, I swear you fixed it in the past. But in 0.2.1b <strong>pack()</strong> is always setting the <strong>table.n</strong> value to 0:</p> <img style="" border=0 src="/media/12874/28_pack0.PNG" alt="" /> https://www.lexaloffle.com/bbs/?tid=39772 https://www.lexaloffle.com/bbs/?tid=39772 Tue, 29 Sep 2020 15:54:59 UTC QoL Suggestion: nop <p>Hey <a href="https://www.lexaloffle.com/bbs/?uid=1"> @zep</a>,</p> <p>I know this is pretty minor, but I often find myself adding this to my programs so that I can use it in tables of functions/behaviors or other similar circumstances:</p> <div> <div style="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 nop() 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>It'd be cool, and kind of in keeping with the half-lua/half-asm feel of PICO-8 to have a handy built-in <strong>nop()</strong> function for such occasions:</p> <div> <div style="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 assign_behavior(o,b,f) o.behavior[b] = f or nop end -- saves me having to do this elsewhere: if(o.behavior[b]) o.behavior[b]()</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>I can't be sure, but I bet it might be useful for some tweetcarts too.</p> <p>Seems like it'd be trivial to add as an efficient built-in C-side function as well. No need to handle args or closures or anything, just spot it and return the empty set immediately.</p> <p>Anyway, I know it's about as minor a request as a person could possibly make, but still, I figured I'd at least ask. ;)</p> <hr /> <p>PS: Honestly, I think even vanilla Lua could use this as an actual built-in, like a pseudo-keyword. In some cases it could be as useful as <strong>nil</strong>.</p> https://www.lexaloffle.com/bbs/?tid=39651 https://www.lexaloffle.com/bbs/?tid=39651 Sun, 20 Sep 2020 13:34:11 UTC Forum issue <p><a href="https://www.lexaloffle.com/bbs/?uid=1"> @zep</a></p> <p>Why does clicking the <strong>Forum</strong> link in the site ribbon always take me to the <a href="https://www.lexaloffle.com/bbs/?cat=7#sub=2"><strong>BBS &gt; PICO-8 &gt; Cartridges</strong></a> subforum?</p> <p>I feel like it ought to be taking me to the <a href="https://www.lexaloffle.com/bbs/?cat=7"><strong>BBS &gt; PICO-8</strong></a> root forum.</p> <p>Even if your intent is to lead new users to the Cartridges subforum so they know it exists, it should really only do that from outside of the forum itself. Once I'm actually in the forum it feels very off to click <strong>Forum</strong> and end up with nothing but carts instead of general PICO-8 discussions. I keep doing this intuitively to return to the root forum, and then I remember I have to click the penultimate breadcrumb instead of the intuitive <strong>Forum</strong> link.</p> https://www.lexaloffle.com/bbs/?tid=39601 https://www.lexaloffle.com/bbs/?tid=39601 Tue, 15 Sep 2020 06:47:31 UTC A constant is more expensive than an addition <p>I saw this mentioned on Discord, so I tested it, and found it to be true. I can't think of a reason for it to be this way, so I figured it should be written up as a bug.</p> <p>This code:</p> <div> <div style="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>local c=x+y</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>is faster than this code:</p> <div> <div style="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>local c=0</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>Here's a dead-simple test cart. Hold a button down to switch from running the first assignment per pixel to running the second. I get stat(1) = 0.7709 for c=x+y and 0.8296 for c=0, when at best they ought to be at least identical.</p> <p> <table><tr><td> <a href="/bbs/?pid=80302#p"> <img src="/bbs/thumbs/pico8_rutesujaju-0.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=80302#p"> c=x+y vs c=0 performance test</a><br><br> by <a href="/bbs/?uid=12874"> Felice</a> <br><br><br> <a href="/bbs/?pid=80302#p"> [Click to Play]</a> </td></tr></table> </p> https://www.lexaloffle.com/bbs/?tid=39090 https://www.lexaloffle.com/bbs/?tid=39090 Mon, 03 Aug 2020 10:03:04 UTC