Discuss Scratch
- Discussion Forums
- » Questions about Scratch
- » How do I stop sounds in a sprite from overlapping?
- SSJ98
-
Scratcher
3 posts
How do I stop sounds in a sprite from overlapping?
I'm making a Parappa type game (a ps1 rhythm game), and when you press a button, it correlates to a specific sound. However it has been overlapping and I can't use a script like this because the music stops as well.
Does anyone have any solutions to this?
when green flag clicked
forever
if <key [x] pressed?> then
stop all sounds
play sound [x]
wait until <not <key [x] pressed?>>
end
end
Does anyone have any solutions to this?
Last edited by SSJ98 (Jan. 21, 2024 02:03:38)
- PhiPhenomenon
-
Scratcher
500+ posts
How do I stop sounds in a sprite from overlapping?
You might need to explain what “overlapping” means. If the sound is currently playing and you press the button again, it restarts the sound from the beginning.
Also, next time you have scripting questions, make sure to post them in Help with Scripts.
Also, next time you have scripting questions, make sure to post them in Help with Scripts.
Last edited by PhiPhenomenon (Jan. 21, 2024 02:06:37)
- SSJ98
-
Scratcher
3 posts
How do I stop sounds in a sprite from overlapping?
Also, next time you have scripting questions, make sure to post them in Help with Scripts.Will do!
Basically what I mean is that if have a sequence like this:
W-W-W
Each W contains a different sound, when I write a script for it, it would look something like this:
when green flag clicked
forever
if <key [w] pressed?> then
play sound [sound1]
wait until <not <<key [w] pressed?>>>
wait until <key [w] pressed?>
play sound [sound2]
wait until <not <<key [w] pressed?>>>
wait until <key [w] pressed?>
play sound [sound3]
wait until <not <<key [w] pressed?>>>
end
end
(That's a basic script I would write not accounting for other measures or anything like that.)
What I want to do is not have sound1 and sound2 not overlap each other when freestyling with quicker rhythms.
- PhiPhenomenon
-
Scratcher
500+ posts
How do I stop sounds in a sprite from overlapping?
Here's my solution:

Sorry for the big image, but it's easier to post it like this.
The mod block means modulus and it gets the remainder after dividing it by the second input. So if soundCounter's remainder after dividing by two gives zero, play the first sound. This allows the sounds to alternate. You can change the 2 to however many sounds you have and add more if conditions under.
This solution is kind of ineloquent but it works, though you need tons of broadcasts

Sorry for the big image, but it's easier to post it like this.
The mod block means modulus and it gets the remainder after dividing it by the second input. So if soundCounter's remainder after dividing by two gives zero, play the first sound. This allows the sounds to alternate. You can change the 2 to however many sounds you have and add more if conditions under.
This solution is kind of ineloquent but it works, though you need tons of broadcasts
Last edited by PhiPhenomenon (Jan. 21, 2024 03:36:59)
- cosmosaura
-
Scratch Team
1000+ posts
How do I stop sounds in a sprite from overlapping?
Glad you found an answer! Since this is resolved, I'll close it to help highlight the answer and prevent future responses. If you need it re-opened, though, you can report this and ask. 

- Discussion Forums
- » Questions about Scratch
-
» How do I stop sounds in a sprite from overlapping?