This cartridge is an exploration about 'how to show things to the player'.
Arrow keys to move, [O] button (usually Z/W key on qwerty/azerty keyboard) to change the view mode.
Sometime, I just make pico stuffs for the pleasure to scratch my head... :-)



I was looking at the code and wanted to share some information about Lua that I think is awesome.
Lua's boolean operators can return non-boolean results:
-
a or b
will returna
if it is notnil
orfalse
, otherwiseb
. a and b
will returna
if it isnil
orfalse
, otherwiseb
.
Notice they simply return one of the inputs, rather than coercing the result into a boolean. They only return a boolean if the returned input is a boolean.
If you know C/C++, then you're probably familiar with the ?:
operator, which does what your iif()
does. You can simulate that with AND/OR:
a ? b : c
== a and b or c
Therefore, you can replace iif()
with less code that's more readable (to me):
function iif(c,t,f) return c and t or f end |
Or, instead of calling v=iif(c,t,f)
, simply inline the v=c and t or f
logic at the call site.
As an aside, this is great for optional arguments:
function error(s,c) color(c or 8) -- supplied color or red if not supplied print(s) end |
Sorry for the long post, but when I found out Lua worked this way, it made me happy, so I wanted to pass on the knowledge. :)



> Is it basically raycasting with limited depth?
I made a function to draw each pixel of a line (Bresemham). I have shown a sample of use at the picoscope 2017. It's a basic raycasting without optimization. This has been used as tutorial (for young and less young peoples).
> a ? b : c == a and b or c
Yes, it's a good tip for pico8 but... You'd better not take the habit to use it because with compiled languages (*) you may have no control of the order of the evaluation. So if, a,b and c are functions : b() can be called first, rather than a(), to evaluate the and operator. I fell into this trap (for the + operator) : http://monkeycoder.co.nz/forums/topic/rval-eval-order/
So take care... This tip can be language and/or platform specific...
;-)
Thanks for the advice. It's very kind to help other people.
(*) c++ 11 respects the order for 'and', 'or' and '?'.



Oh absolutely, that tip was very specific to Lua.
A good language will do it the same way, though not as conveniently if the types are not dynamic.
C/C++ does boolean short-circuiting pretty well. I've often done this sort of thing:
if (s!=nullptr && s->blah) { // ... } |
Because I know evaluation will stop before s->blah if s==nullptr.
Unfortunately, C/C++ boolean logic results are coerced to true/false, so the nifty default-value trick wouldn't work:
color( c || 8 ); |
That'd just pass true
, always. Probably give a compiler warning, in fact, e.g. "boolean expression is const."



Yes
Nice to meet you. I like the catridge you made with the boing ball like the Amiga demo.
I like what you have done with pico8 and the way you do it.
Would you like to give me your twitter tag?
Mine is @wdwave
Have a good day
jihem



I don't really use twitter. The format frustrates me. :) I avoid social media in general. I just hover over forums that interest me.
I should point out that someone else made the majority of that Boing demo. All I did was tweak a few things and the sfx to make it as faithful as possible, since I loved my Amiga back in the day and I always thought the Boing demo was amazing. Now I know they were cheating, but it's still amazing for being clever. :) Anyway, I wouldn't want to take credit for something I didn't do.



I like it... You could easily turn it into a proper "Bat Simulator" by (1) removing the ability to "turn on the light" and (2) having a moving target (say a juicy moth ;-) that you must chase while avoiding obstacles.
[Please log in to post a comment]