u/VeryNaughtyBoy42

▲ 5 r/pico8

Coroutines help needed

I'm trying to get my head around coroutines by creating a simple "ticker" - that is, pass it a string and it prints it slowly one character at a time, a bit like Gameboy text. I've got it working, sort of, but the screen doesn't clear despite the cls() in _draw() and the program crashes after all the text is displayed. I tried using costatus() but it doesn't return anything. Please help, what am I doing wrong?

function _init() 
 t=cocreate(ticker("this is a test"))
end

function _update()
 coresume(t)
end

function ticker(str)
 local l=#str
 for p=1,l+1,0.2 do
  print(sub(str,1,p),0,0)
  yield()
 end
end

function _draw()
 cls()
end
reddit.com
u/VeryNaughtyBoy42 — 7 days ago
▲ 28 r/pico8

John Conway's "Game of Life"

If you're getting on a bit like me, you might remember these "Life" simulations. They were a popular project on early home computers. If you're not familiar with it, it starts with a grid of randomly created "cells" that are either "alive" or "dead", and there are rules to determine if each cells dies, stays alive, or is newly created, depending on how many live cells are around it. With each successive "generation" the grid evolves and can spawn all sorts of interesting patterns, shapes that move across the grid, and so on. It can be quite meditative to watch. If you'd like a deeper overview, the Wikipedia article is excellent: https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life

Here's the cartridge: https://www.lexaloffle.com/bbs/?tid=158250

https://i.redd.it/6mqmc1ynwveh1.gif

reddit.com
u/VeryNaughtyBoy42 — 28 days ago
▲ 9 r/pico8

What is wrong with this code?

It's the basis of making a simple star field.

I create an array for an individual star (star), then an array of those arrays (stars). I use a loop to set the individual values for each star, and (for debugging) print out the values. They're different as expected. But immediately afterwards, they all become the same value - the value of the last item added.

Here's the output:

-0.6718
-0.5777
0.0473
-0.2585
0.6657
-0.0112
-0.392
-0.5346

-0.392
-0.5346
-0.392
-0.5346
-0.392
-0.5346
-0.392
-0.5346

And here's the code ...

function _init()
 star={0,0,0,0,0}
 stars={}
 numstars=4

 -- populate the array
 for c=1,numstars do
  add(stars,star)
 end

 -- create all the stars
 initstars()
end

function initstars()
 for s=1,numstars do
  initstar(s)
 end

 -- for debugging, now show the x inc and y inc values for all the stars
 print("")
 for s=1,numstars do
  print(stars[s][4])
  print(stars[s][5])
 end
end

function initstar(s)
 local ang=rnd(1)
 local spd=rnd(1)

 stars[s][1]=64 -- x
 stars[s][2]=64 -- y
 stars[s][3]=0  -- colour
 stars[s][4]=cos(ang)*spd  -- x inc
 stars[s][5]=sin(ang)*spd  -- y inc

 -- for debugging, print out the x inc and y inc values
 print(stars[s][4])
 print(stars[s][5])
end
reddit.com
u/VeryNaughtyBoy42 — 2 months ago

I found this Youtube video today and ended up watching her a play a lot. I love the stripped back arrangement, where it seems all the real action is in the left hand and as far as I can tell the right hand is only doing the melody. Can someone please explain to me how she's arriving at that left hand arrangement?

https://www.youtube.com/watch?v=5KDY2ESpZ_I

u/VeryNaughtyBoy42 — 4 months ago