Log In  
BBS > Lexaloffle Community Superblog
This is a combined feed of all Lexaloffle user blogs. For Lexaloffle-related news, see @zep's blog.

All | Following | PICO-8 | Voxatron | General

Cart #saturn91sparticles-0 | 2021-10-20 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

This is an example for an easy to use particle system.

to use it in your own cartridge do the following: copy the code in tab1 into one of your code tabs

Use it in the project as follows:

function _init()

function _update()
    if btnp(🅾️) then
            {x=63, y=63},   //pos on screen
            10, //num of particels
            2,  //life time (in sec)
            0,  //form 0=rnd 1=pixel,2=circles,3=rect
            2,  //size
            3,  //color
            2   //speed of particles

function _draw()
    print("press 🅾️ for burst", 32, 40, 7)
P#98894 2021-10-20 10:11

Cart #nejedesyo-0 | 2021-10-20 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

This is a cooperative game where both players must work together to solve each puzzle.

Created as a fun project between Chris Delay (dad) and his two kids Leon & Elliot, aged 9 and 6 at the time. All graphics, sounds, music and level design by Leon & Elliot, with coding and puzzle design support from Chris.


P#98892 2021-10-20 09:45

I am trying to use values in a table to dictate which scene is being shown in the game. I defined the table 'S' at the top of the code but a piece at the bottom referring to it comes back nil. What's the problem?

function _init()



    if s.menu>0 then
        screen_menu() end
    if s.start>0 then
        screen_start() end
    if s.t1>0 then
     screen_t1() end
    if s.one>0 then
P#98887 2021-10-20 09:37

This game is a remix of the adventure game tutorial by @MBoffin.

About my game: I made for the first time ,so it's a simple game.
The theme was the way back from the lumberjack one day.
Let's go to the red circle.

           Thank you for playing.
Cart #ruwotuwemi-0 | 2021-10-20 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
P#98886 2021-10-20 07:28

Cart #ghost-0 | 2021-10-20 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

This game is a remix of the adventure game tutorial by @MBoffin.

About my game:
Please defeat a ghost! Let's get ready to search for a room, and to defeat a ghost.
You should pay more attention. You are killed when I do not prepare.

Thank you for playing.

P#98880 2021-10-20 04:23

Cart #arrowsconfusion-0 | 2021-10-20 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

This game is a remix of the adventure game tutorial by @MBoffin.

About my game:

The theme of this game is escape from a mysterious laboratory.
You control a red stickman who must avoid the needle traps and head for the goal point, the flag.
If you step on the arrow tiles on the floor, you will be forced to move in that direction, so you have to be careful.

How to play:
Cursor key...Move
X key...Retry game(Only when the game is over.)

Thank you for playing.

P#98875 2021-10-20 01:33

PICO-8 + Nature of Code + ECS = piconoc.

Emergent ecosystem behaviors for agents in Pico-8. Based on Daniel Schiffman's "Nature of Code". Uses Entity Component Systems.

Cart #piconoc_ecosystem-5 | 2021-10-20 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

Hi! I want to simulate flies and frogs and lizards and spaceships and such in PICO-8. And I want to do so in ways that give surprising results. PLUS I want to refine my understanding of Entity Component Systems (ECS). This cart holds my efforts to do all those things.

Critters should be recognizable by their behaviors, not the graphics and/or sounds.

This is a very early learning project in process.

More details and source code;

Critters in progress:

  • flies (implemented!)
  • frogs (implemented!)
  • rabbits
  • snakes
  • cows?
  • aliens?
  • Cthulhu?

When a fly hits the borders, it makes a "blatt" sound. Because flies make annoying sounds in real life. So authentic!

The framework will ideally make it possible to simply add data without lots of customized functions for each critter's particular behavior. I'm not there yet. But I'm getting there.

P#98876 2021-10-20 01:32 ( Edited 2021-10-20 01:45)

Cart #groundwars-0 | 2021-10-19 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

Inspired by fond memories of Liero I present Ground Wars, my first Pico-8 release!

Battle a friend in randomly generated caverns on a fully destructible map in this top-down shooter. Choose your loadout from an arsenal of 7 unique deadly weapons at the start, and pickup supply creates to suit up during a match. Be careful though: contents are volatile!


Movement - Arrow keys

Fire - X

Dig - O

Change weapon - Hold O, Press X to cycle

Pickup crate - Hold O when nearby

Thanks to WarrenMarshall for writing the excellent vector math library I used in this project!

P#98874 2021-10-19 22:37

Cart #duckpond2-0 | 2021-10-19 | Code ▽ | Embed ▽ | No License

P#98862 2021-10-19 15:57

So I want to make a sound effect that only plays when a direction is pushed, and the trouble that I'm running into is that:

  • using (btn(input)) loops the sound so fast it almost crashes PICO-8
  • using (btnp(input)) only plays it when the button is first pressed

How do I make it so it plays consistently while pressing a direction, and loops at a normal speed? I tried making a timer that gets added to while a direction is pushed, but the only way I could find to do it was i+=1 which only added 1 a single time. Is a timer the right way to go or is there a more efficient way?

function move_player()

    if (btn(⬅️)) then 
        newx-=.1 p.sprite=d.left sfx(0)
            elseif (btn(➡️)) then 
                newx+=.1 p.sprite=d.right sfx(0)
                    elseif (btn(⬆️)) then
                         newy-=.1 p.sprite=d.up sfx(0)
                        elseif (btn(⬇️)) then
                             newy+=.1 p.sprite=d.down sfx(0)

Here's a snippet of my code if it helps. Thanks!

P#98842 2021-10-19 01:09

PICO-8 has been my obsession for the last few months but math is my always obsession and lately I've been having a lot of fun playing around with various aspects of geometry so when I hit a weird bug in my other project I decided to take a break and shift gears a bit. So I threw together a little interface for working with 2D signed distance fields/functions.

It's fairly hefty at a little over 500 tokens so probably not super useful generally speaking but pretty fun to play with, if I do say so myself.

Here are a couple series of images I've created so far. In each, all of the images are made from the same SDF and just messing with how colours are assigned based on the distance.

That last one is my attempt at a ripply/watery reflection which, I think, didn't come out too badly.

And some hearts.

If you're not familiar with them, SDFs are frequently used with a ray marching technique to render 3D scenes as a faster alternative to ray tracing. (See Inigo Quilez's work for some stunning examples of this in action. Or basically anything on shadertoy.) Anyway, ray marching is basically just a collision detection algorithm so, apart from making pretty pictures, an SDF can also double as actual level geometry.

In the cart below I took the same SDF that was used to generate the image and used it to turn the pool/fountain thing into a collide-able part of the scenery. (In fairness, I'm not actually using ray marching here I'm really just checking for when the distance goes from positive to negative. But you could do better/smarter things if you really wanted to.)

Cart #punujehibi-0 | 2021-10-18 | Code ▽ | Embed ▽ | No License

In this one I just threw together a bunch of random geometry. Move around with the arrow keys and press Z to cycle which distance field(s) are visible: none, interior, exterior, or both.

Cart #ragahegaro-0 | 2021-10-18 | Code ▽ | Embed ▽ | No License

P#98824 2021-10-18 20:56 ( Edited 2021-10-18 20:56)

Apologies if this is a duplicate, I'm new to the forums and couldn't find anything similar when searching.

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

I've broken it down so you can use the following snippet to observe the issue (pico-8 0.2.3)

function pen_col()
 return peek(0x5f25)&0xf

color() -- reset pen colour

print("default colour",0,0)

print("nil produces black",0,6,nil)

print("draw state is now black",0,12)

color() -- reset pen colour
print("colour parameter containing nil is black",0,18,_c)

color() -- reset pen colour
print("back to default colour",0,24)

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.

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#98821 2021-10-18 17:52

Cart #calendar-0 | 2021-10-18 | Code ▽ | Embed ▽ | No License

A customizable calendar.


  • Real-time changes: textcolor/backcolor of each item, language, first day of week, country
  • Languages: en, nl, fr, de, es, it
  • When holiday translation not available for specific language -> default english

  • Fixed holidays
  • Calulated holidays (e.g. easter/pentecost/....)
  • Payed/Normal holidays per country (only Belgium for the moment)
  • Holiday banner

  • Colors, language, first day of week and country are saved in cartdata
  • "Reset all" function
P#98816 2021-10-18 13:19

Here's a function that will transform whatever you pass it into a table that will hopefully be understandable by a human. It'll take any table or other Lua value, so you can, for example, print it:


The only parameter besides the string to be transformed is the depth.

local deep={l1={l2={l3={l4="!"}}}}}
print(ins(deep)) --prints everything
print(ins(deep,2)) --stops at l2 and prints {_}

Cart #ins_inspectforpico8-2 | 2021-10-18 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

As the author of the inspect.lua library, I use it a lot on my day job when I need to debug Lua, and I really miss it when debugging in Pico-8. I found some previous efforts on this direction, but I was missing a lot:

  • Marking repeated tables, functions, threads and userdata with numbers
  • Handling nested tables / avoiding printing repeated tables
  • Sorting keys sensibly
  • Printing metatable data
  • Presenting arrays as comma-separated single lines, and hashes in multiple-span lines

I made ins' output take less horizontal space than inspect.lua, so it adapts better to PICO-8's output. And I trimmed features(string escaping, preprocessing).

Still, at ~700 tokens, it's ... a chunky boy. You probably shouldn't add it to your project permanently. Think of it as a "debug artillery" function: deploy it to a tab in your game, it should be able to handle whatever you throw at it and return a digestible string. Once you have used it to destroy your problem, remove it.

PS: My biggest surprise was that PICO-8 has no built-in sorting function. So I bundled one. Oh and there is no concat, either. The garbage collector must be having fun with all those strings :)

EDIT: fixed bug in isidentifier function

P#98806 2021-10-17 23:37 ( Edited 2021-10-18 20:34)

Cart #zanepetuzo-0 | 2021-10-17 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

hi, so I was talking to my friend some time ago and we were discussing how to make randomly generated music better, and we ended up talking about generating the chord progression and the time signature first and then picking the notes randomly from there, he didn't believe this would work so here's my proof of concept, feel free to read the code and tell me some thoughts

and for the name of the cartridge, "c3510"(pronounced cesio) is a robot from a distopian worldbuilding i'm creating, he loves experimenting with music, so I thought it would be interesting to theme this cartridge as his "futuristic music box"

P#98801 2021-10-17 19:51

Cart #kipopeyema-0 | 2021-10-17 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

P#98798 2021-10-17 18:44

Early on in playing around with PICO-8 I wrote a function to print text with a black outline.

function prt_out(s,x,y,c)

I imagine a lot of people have also done this and I can't be the only person who found it a bit clumsy and, near the end of a project when casting about for tokens, wondered if those five very similar print calls couldn't be reduced.

Nowadays we have P8SCII so I thought I'd have a look. Here are some candidates I've written with their token counts and times from my crude testing:

function p1(s,x,y,c) -- 42 tokens, 5.6 seconds
?'\f0\-f'..s..'\^g\-h'..s..'\^g\|f'..s..'\^g\|h'..s..'\^g\f'..chr(c+(c>9 and 87 or 48))..s,x,y

function p2(s,x,y,c) -- 26 tokens, 6.2667 seconds
for i in all(split'\f0\-f,\-h,\|f,\|h') do

function p3(s,x,y,c) -- 38 tokens, 5.6667 seconds

function p4(s,x,y,c) -- 30 tokens, 5.7 seconds

function p5(s,x,y,c) -- 42 tokens, 6.1 seconds

function p6(s,x,y,c) -- 29 tokens, 6.2 seconds
for _,i in pairs{'\f0\-f','\-h','\|f','\|h'} do

function p7(s,x,y,c) -- 37 tokens, 6.2667 seconds
for i in all{'\f0\-f','\-h','\|f','\|h','\f'..chr(c+(c>9 and 87 or 48))} do

'?' vs print makes no difference to performance, but does save characters and 1 token each use.

I was rather surprised that p2 uses so few tokens and isn't that slow. Also that p1 is actually the fastest (but only just).

I usually find that tokens are more precious to me than a tiny bit of performance so I'm likely to use p2 above. p4 is pretty cheap at 30 tokens and faster than the naive approach so perhaps it's an overall winner (so far).

I'm very interested to know if anyone has a better way(?)

v1 edit:

  • freds72's suggestion is p6. 3 more tokens for .0667 seconds faster. Using pairs() instead of all() causes half of that saving.
    I thought removing the split might make more difference than that, but now I feel a bit better about having split all over my game code to save tokens(!)
  • I removed the unnecessary '\^g' (go home) parts from the P8SCII snippets where appropriate. This saves some characters and performance (but also somehow saved the odd token and I'm not sure how).

Cart #drakeblue_prt_out-1 | 2021-10-18 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

(Please use any of these functions if you want)

P#98796 2021-10-17 18:19 ( Edited 2021-10-18 08:59)

I wrote a blog post about making a generic method dispatch helper for 'foreach'.
It's more of a novelty than something really worth adding to code. It's better to just use 'for x in all(XS)' instead.

Here's the mini summary:

function callm(method, ...)
 local params={...}
 return function(o)
  if type(o)=="table" then
   local m=o[method]
   if type(m)=="function" then

function _draw()
 foreach(drawable, callm("draw", 11))

Check it out: https://kallanreed.com/2021/10/17/pico-8-generic-dispatch-with-parameters/

P#98795 2021-10-17 17:56 ( Edited 2021-10-18 02:09)

Hey, I've recently taken a shot at bringing my digital-ink project perfect-freehand over to Pico8.

Cart #perfectfreehand0-0 | 2021-10-17 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

The idea is to render input points as polygons (or meshes, in this case) with variable widths. This one is not quite finished but I've found it so far an excellent challenge to improve the algorithm's performance and see how it would handle meshes rather than filled polygons. There's a lot more improvement to be done there—feel free to snoop around if you'd like!

P#98787 2021-10-17 12:19

Cart #zelda1_dungeon_2021_10_17-0 | 2021-10-17 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

P#98785 2021-10-17 12:03
View Older Posts
Follow Lexaloffle:        
Generated 2021-10-20 13:37:23 | 0.110s | Q:91