JehtBlack [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=34963 Passing nil colour to draw functions change draw state pen colour to black <p>Apologies if this is a duplicate, I'm new to the forums and couldn't find anything similar when searching.</p> <p>I was making some centred variants of graphics functions and found that omitting the colour parameter would result in the pen colour being set to black</p> <p>I've broken it down so you can use the following snippet to observe the issue (pico-8 0.2.3)</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 pen_col() return peek(0x5f25)&amp;0xf end cls(1) color() -- reset pen colour print(&quot;default colour&quot;,0,0) assert(pen_col()==6) print(&quot;nil produces black&quot;,0,6,nil) assert(pen_col()==0) print(&quot;draw state is now black&quot;,0,12) assert(pen_col()==0) color() -- reset pen colour _c=nil print(&quot;colour parameter containing nil is black&quot;,0,18,_c) assert(pen_col()==0) color() -- reset pen colour print(&quot;back to default colour&quot;,0,24) assert(pen_col()==6)</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>In my usage this means that if I wrap for example print, I'll want to forward the colour value, but allow for it to be omitted, in order to work around the bug I have to read the current pen colour from the draw state to prevent draw state defaulting to black.</p> <p>I'd consider this a bug since passing nil colour should behave the same as omitting the colour parameter from the built in draw functions.</p> https://www.lexaloffle.com/bbs/?tid=45034 https://www.lexaloffle.com/bbs/?tid=45034 Mon, 18 Oct 2021 17:52:52 UTC