astinad [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=40543 Horribly named variables in the included demos <p><code>function very_tiny_silly_but_also_hey_WTF_rant()</code></p> <p>Could the built-in demo variable names be any less helpful for n00bs? From demos/hello:</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>for i=1,11 do for j0=0,7 do j = 7-j0 col = 7+j t1 = t + i*4 - j*2 x = cos(t0)*5 y = 38 + j + cos(t1/50)*5 pal(7,col) spr(16+i, 8+i*8 + x, y) 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> <p>What does j0 mean? jack0ff? What about j for that matter? I see col, which could mean column, but then I would expect row or something similar for a multi-dimension loop. t1? The t-1000 terminator? Bah! Humbug! </p> <p>There's a ton of greatly helpful advice in the pico zines and in the forums here, but it just strikes me as frustrating to show n00bs the hello world demo and it just purposely uses these incredibly unhelpful variable names. I've always been taught that function names and variable names should be self explanatory as to their purpose for ease of code reading, particularly in an example meant to demonstrate program functionality.<br /> <code>end</code></p> https://www.lexaloffle.com/bbs/?tid=36383 https://www.lexaloffle.com/bbs/?tid=36383 Fri, 27 Dec 2019 04:18:08 UTC Does print() in _update() work? <h1>Does print() in _update() work?</h1> <p>Hi there! Just purchased PICO-8 and Voxatron last week and I'm trying to recreate some classic pong action as a way of getting familiar with the ins and outs of the scripting environment (this is my first time ever interacting with anything related to Lua). Right now I've got a paddle that responds to up/down keyboard presses and a ball that bounces around the screen and collides with the paddle. </p> <p>I'm trying to print some debug text at the moment of paddle + ball collision, but my <em>print</em> function appears to be doing nothing. </p> <p>Here's what my current gameplay looks like:</p> <img style="margin-bottom:16px" border=0 src="https://www.lexaloffle.com/bbs/files/40543/ball_example.gif" alt="" /> <p>And here's the code:<br /> (the print function that appears to not be working is in line 53 - i.e. the 3rd line from the bottom)<br /> (unrelated: sure would be nice to have line numbers on code snippets here in the forums!)<br /> <div><div><input type="button" value=" Show " onClick="if (this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display != '') { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = ''; this.innerText = ''; this.value = ' Hide '; } else { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = 'none'; this.innerText = ''; this.value = ' Show '; }"></div><div><div style="display: none;"></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>ball_x = 64 ball_y = 64 ballspeed_x = 3 ballspeed_y = 2 pad_x = 20 pad_y = 50 pad_w = 4 pad_h = 20 function _draw() rectfill(0,0,127,127,5) circfill(ball_x,ball_y,2,14) rectfill(pad_x, pad_y, pad_x + pad_w, pad_y + pad_h, 10) end function _update() moveball() updateballcollisions() movepaddle() updatepaddlecollisions() end function moveball() ball_x += ballspeed_x ball_y += ballspeed_y end function updateballcollisions() if (ball_x &lt; 0 or ball_x &gt; 127) then ballspeed_x *= -1; end if (ball_y &lt; 0 or ball_y &gt; 127) then ballspeed_y *= -1; end end function movepaddle() if btn(2) and pad_y+(pad_h/2) &gt; 0 then pad_y -= 4 end if btn(3) and pad_y+(pad_h/2) &lt; 127 then pad_y += 4 end end function updatepaddlecollisions() pad_top_y = pad_y pad_bot_y = pad_top_y + pad_h pad_left_x = pad_x pad_right_x = pad_left_x + pad_w if ((ball_x &gt; pad_left_x) and (ball_x &lt; pad_right_x) and (ball_y &gt; pad_top_y) and (ball_y &lt; pad_bot_y)) then ballspeed_x *= -1 print(&quot;paddle collision&quot;, 6, 6, 11) 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> <p></div></div></div></p> <p>As you can see in the gameplay gif, my <em>updatepaddlecollisions()</em> function seems to be working correctly when the ball collides with the paddle except that there should also be a string &quot;paddle collision&quot; that prints at (6, 6) colored green (color 11), but that string never prints! :(</p> <p>I'm aware of the <em>print<strong>h</strong>()</em> function but I'd really like to stay within the editor and just have my debug text print directly onto the app screen. </p> <p>So! Am I crazy or does the <em>print()</em> function not work if it's in <em>_update()</em> or some function that gets called within <em>_update()</em>? Thanks so much! I'm so excited to actually build cooler things with this amazing tool! </p> https://www.lexaloffle.com/bbs/?tid=35684 https://www.lexaloffle.com/bbs/?tid=35684 Thu, 17 Oct 2019 17:52:48 UTC