Some quick bullets to set the stage for platform / SDK version:
- I'm developing on MacOS
- Using Playdate Lua SDK 2.5.0 with the Noble Engine
The title I hope captures the issue at the high level. I've set a callback function for the fileplayer, but it seems to fire "immediately". I'm building a rhythm game (see here).
This is the code I have (I set the fileplayer up elsewhere, including loading the song). It's called in the NobleScene start() function:
music:play()
music:setFinishCallback(self:onSongComplete())
The callback function transitions from my play scene to a "Song Results" scene (scenes are NobleScene classes from Noble Engine). Right now it's very barebones:
function scene:onSongComplete()
Noble.GameData.set("Score", score)
Noble.transition(SongFinish, nil, Noble.Transition.SlideOff)
end
The issue is, despite setting the callback after the fileplayer starts playing, when the play scene starts it immediately transitions to the song results screen.
What have I tried so far?
I tried, in the callback function, setting a conditional statement to see if the fileplayer is not playing via "playdate.sound.fileplayer:isPlaying()" and checking if it's false.
This didn't work. My assumption is because the callback is being called before the song actually starts playing, causing the isPlaying() to still return false, allowing the code to proceed.
On a lark, I also tried yielding before setting the callback function (I don't know why I thought this would work), and nope... didn't work!
This then leads me to the question: how do I fix this? I'm guessing there's some collision issue happening here where despite play() being called just before this the callback is getting called ahead of it, stopping the player from actually being able to play the game.