recordToSample callback only working once - Bug or Lua nOOb?

I've had this problem before but can't rememeber how I coded around it, I've run into it again so have broken it down to the simplest code I can, the output of the code below is always:


The callback only works once, is this something I'm missing in Lua or a bug with the API?

buffer = nil
slot = 0
function recordSample()
	buffer =, playdate.sound.kFormat16bitMono)
	playdate.sound.micinput.recordToSample(buffer, function(sample)
		slot += 1
		sample:save("" .. slot)


function playdate.update()

(dupe of Dave Hayden πŸŠπŸ€ΈπŸ»β€β™‚οΈ: " So the root problem is I j…" - so we have a copy here)

So the root problem is I just didn't expect anyone would recurse in this way. :sweat_smile: When recording finishes we get the callback function from a global reference, call it, then clear it--missing that it'd been reset in the callback. I'll try and get this working right, but in the mean time a workaround is to instead set a flag in the callback that you pick up in update() to indicate you should start recording again.

1 Like