Skip to content

Instantly share code, notes, and snippets.

@neilpopham
Last active April 5, 2020 21:03
Show Gist options
  • Save neilpopham/72e0e63e42a4ae07e977fcfcf102c085 to your computer and use it in GitHub Desktop.
Save neilpopham/72e0e63e42a4ae07e977fcfcf102c085 to your computer and use it in GitHub Desktop.
local sfxcache = {
channel=1, -- the channel to check (1-4)
beats=8, -- fire on every nth beat (0, 4, 8, or 16)
sfx={},
valid=true,
play=function(self,...)
add(self.sfx,{...})
end,
check=function(self)
if stat(19+self.channel)%self.beats==0 then
if #self.sfx>0 and self.valid then
for s in all(self.sfx) do
sfx(s[1],s[2] or -1,s[3] or 0,s[4] or 0)
end
self.sfx={}
self.valid=false
return true
end
else
self.valid=true
end
return false
end
}
function _init()
music(29)
end
function _update60()
if btnp(4) then
sfxcache:play(1)
end
if btnp(5) then
sfxcache:play(2)
end
sfxcache:check()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment