Discuss Scratch

akaCarbone
New Scratcher
4 posts

Stop Forever Loop Sounds

HI all,

Based in this thread:
https://scratch.mit.edu/discuss/topic/184228/?page=1#post-1800824

I've implemented ErnieParke's solution, however, it did not work for me (not sure if I'm missing something).

I have the following code under the stage:

when green flag clicked
set [stopBGM v] to [0]
forever
if <[stopBGM] = [1]> then
stop all sounds
else
play sound [GameTheme v] until done
end

However, when I change the
 (stopBGM) 
variable value to 1, the song is not finished yet, so the forever loop doesn't evaluate the change and doesn't stop the music.

Is there a way to stop the song without making it restart immediately after?

Thanks!!!!
logais
Scratcher
100+ posts

Stop Forever Loop Sounds

Hi akaCarbone,
The code you’re using is right, just missing one block. Change the code to this:
when green flag clicked
set [stopBGM v] to [0]
forever
if <[stopBGM] = [1]> then
stop all sounds
stop [this script v]
else
play sound [GameTheme v] until done
end
Hope it helps,
Logais

P.S. If you found this helpful, please consider following me for more help with projects

Last edited by logais (Aug. 24, 2020 05:57:49)

deck26
Scratcher
1000+ posts

Stop Forever Loop Sounds

You need to be able to either stop the playing script or stop all sounds in a separate script.

For example, to constantly play a sound but be able to change which sound you're playing you can just do.

forever
play sound (soundname) until done
end

when [ v] key pressed
set [soundname v] to [sound to play]
stop all sounds

Last edited by deck26 (Aug. 24, 2020 08:03:02)

akaCarbone
New Scratcher
4 posts

Stop Forever Loop Sounds

Thanks logais, deck26 and ScratchDuel :-)

Appreciate the help.
After splitting the loop, it worked like a glove.

Thanks again!

Powered by DjangoBB