Before proceeding, please use the forum search feature at the top of the page to check if your question has already been answered.
How do I…
Play, then pause, then resume a music file on a single channel by pressing/releasing the same key for each.
What is the expected result
In my example from the screenshot, I believe that when a player releases the “p” key, my music file “Weezin’” should play. And then while the file is playing, if the “p” key is released again, the music should pause. And then if it is released once more, the music should resume.
What is the actual result
What actually happens is that the “p” key just restarts the music file with each release.
You’ve created a chain reaction or domino effect. The events are executed from top to bottom. Each action is making the next condition true. It’s a common mistake.
if music is not paused and not playing then play
if playing then pause
if paused then resume
The play music isn’t as reliable as the play sound. The play sound is the recommended method.
There are multiple ways of doing this. For 2 states toggling a Boolean variable works. For more than 2 states, I’ll sometimes use a Boolean variable to track when a change has been made.