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.
Project files (optional)
I tried to include a .zip project file, but I have not done that before and could not figure out how to insert it here. Thank you.
Check if same thing happens with play SOUND on channel
Use something like this instead.
I just tested it an it works perfectly. You can use play music on channel but it’s usually better to use play a sound.
If you want it to restart on the fourth click, change the last event to 0 instead of 1.
You need a variable so that all sub events are not instantly executed one after the other.
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.
Man, you guys all gave excellent solutions. Cannot thank you enough. A bunch of rockstars you are!