Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Instead of stopping all sounds, how to stop a specific sound?
- Benur21
-
100+ posts
Instead of stopping all sounds, how to stop a specific sound?
Instead of stopping all sounds, how to stop a specific sound?
Because I need a music always repeating when it's on the backdrop1 (example)…
But if the backdrop switches to backdrop2, the music will be running “until done”! And if I have other sounds I want to be running, how can I stop only the music?
I think it is a block that needs to be added…
stop all sounds
Because I need a music always repeating when it's on the backdrop1 (example)…
when backdrop switches to [backdrop1 v]
forever
if <(backdrop name) = [backdrop1]> then
play sound [mymusic v] until done
end
end
But if the backdrop switches to backdrop2, the music will be running “until done”! And if I have other sounds I want to be running, how can I stop only the music?
I think it is a block that needs to be added…
stop sound [ v]
Last edited by Benur21 (April 1, 2016 22:28:21)
- asivi
-
1000+ posts
Instead of stopping all sounds, how to stop a specific sound?
You may adjust the volume level with this block
set volume to () % // 0% to mute having this sound alone in the sprite
Last edited by asivi (April 1, 2016 22:33:33)
- Benur21
-
100+ posts
Instead of stopping all sounds, how to stop a specific sound?
You may adjust the volume level with this blockset volume to () % // 0% to mute having this sound alone in the sprite
But this will set volume to 0 to all sounds, will not it? How do that block knows what sound it will set the volume to 0?
- Carpit999
-
100+ posts
Instead of stopping all sounds, how to stop a specific sound?
Lets say i have 2 sounds, ‘'carrot’' and ‘'bumps’' and i want to stop only bumps, while it is 50 secs in. However, we will have to say that tempo 50 makes it 50 times as fast. So if 10 beats took 1 second, then tempo 50 would make it 500 beats a second. Assuming this is the case, you would do this:
stop all soundsYou would really set the tempo to 0 bpm then set the tempo to 30000 bpm, (assuming it's 10 beats a second) because it's 500 beats in so you just multiply that by 60. So here's how it would look assuming its 10 bps:
play sound [carrot v] until done
set tempo to (0) bpm
change tempo by (50)
wait (1) secs
change tempo by (-49)
stop all sounds
play sound [carrot v] until done
set tempo to (0) bpm
set tempo to (30000) bpm
wait (1) secs
set tempo to (600) bpm
- footsocktoe
-
1000+ posts
Instead of stopping all sounds, how to stop a specific sound?
Instead of stopping all sounds, how to stop a specific sound?
stop all sounds
Because I need a music always repeating when it's on the backdrop1 (example)…when backdrop switches to [backdrop1 v]
forever
if <(backdrop name) = [backdrop1]> then
play sound [mymusic v] until done
end
end
But if the backdrop switches to backdrop2, the music will be running “until done”! And if I have other sounds I want to be running, how can I stop only the music?
I think it is a block that needs to be added…stop sound [ v]
Try this…
when backdrop switches to [backdrop1 v]
repeat until <not <(backdrop #) = [1 ]>>
play sound [ v] until done
end
- gdpr533f604550b2f20900645890
-
1000+ posts
Instead of stopping all sounds, how to stop a specific sound?
That script still has the same problem. The condition is only checked once the sound has completed. Try this…when backdrop switches to [backdrop1 v]
repeat until <not <(backdrop #) = [1 ]>>
play sound [ v] until done
end
Liam48D has a solution: https://scratch.mit.edu/projects/96146764/
- Carpit999
-
100+ posts
Instead of stopping all sounds, how to stop a specific sound?
Nothing is wrong with mine.That script still has the same problem. The condition is only checked once the sound has completed. Try this…when backdrop switches to [backdrop1 v]
repeat until <not <(backdrop #) = [1 ]>>
play sound [ v] until done
end
Liam48D has a solution: https://scratch.mit.edu/projects/96146764/
- footsocktoe
-
1000+ posts
Instead of stopping all sounds, how to stop a specific sound?
That script still has the same problem. The condition is only checked once the sound has completed. Try this…when backdrop switches to [backdrop1 v]
repeat until <not <(backdrop #) = [1 ]>>
play sound [ v] until done
end
Liam48D has a solution: https://scratch.mit.edu/projects/96146764/
Either one wants the sound to loop over and over or one doesn't. Liam48D's solution is interesting.
Last edited by footsocktoe (April 2, 2016 18:59:13)
- gdpr533f604550b2f20900645890
-
1000+ posts
Instead of stopping all sounds, how to stop a specific sound?
I don't think the tempo affects sound assets. Nothing is wrong with mine.
Your solution does not stop a sound in the middle of it playing. Either one wants the sound to loop over and over or one doesn't.
- Carpit999
-
100+ posts
Instead of stopping all sounds, how to stop a specific sound?
The tempo speeds up the beats, so it is faster.I don't think the tempo affects sound assets. Nothing is wrong with mine.Your solution does not stop a sound in the middle of it playing. Either one wants the sound to loop over and over or one doesn't.
- asivi
-
1000+ posts
Instead of stopping all sounds, how to stop a specific sound?
That block is only for the sounds in the sprite where you put it.You may adjust the volume level with this blockset volume to () % // 0% to mute having this sound alone in the sprite
But this will set volume to 0 to all sounds, will not it? How do that block knows what sound it will set the volume to 0?
- footsocktoe
-
1000+ posts
Instead of stopping all sounds, how to stop a specific sound?
I don't think the tempo affects sound assets. Nothing is wrong with mine.Your solution does not stop a sound in the middle of it playing. Either one wants the sound to loop over and over or one doesn't.
Given his condition that no other sounds playing can stop, I don't think what he wants is possible.
- gdpr533f604550b2f20900645890
-
1000+ posts
Instead of stopping all sounds, how to stop a specific sound?
I tested out the tempo blocks. Like I suspected, they only work with note blocks.The tempo speeds up the beats, so it is faster.I don't think the tempo affects sound assets. Nothing is wrong with mine.Your solution does not stop a sound in the middle of it playing. Either one wants the sound to loop over and over or one doesn't.
- gdpr533f604550b2f20900645890
-
1000+ posts
Instead of stopping all sounds, how to stop a specific sound?
That is what Liam48D's solution does!I don't think the tempo affects sound assets. Nothing is wrong with mine.Your solution does not stop a sound in the middle of it playing. Either one wants the sound to loop over and over or one doesn't.
Given his condition that no other sounds playing can stop, I don't think what he wants is possible.
- asivi
-
1000+ posts
Instead of stopping all sounds, how to stop a specific sound?
Lets say i have 2 sounds, ‘'carrot’' and ‘'bumps’' and i want to stop only bumps, while it is 50 secs in. However, we will have to say that tempo 50 makes it 50 times as fast. So if 10 beats took 1 second, then tempo 50 would make it 500 beats a second. Assuming this is the case, you would do this:stop all soundsYou would really set the tempo to 0 bpm then set the tempo to 30000 bpm, (assuming it's 10 beats a second) because it's 500 beats in so you just multiply that by 60. So here's how it would look assuming its 10 bps:
play sound [carrot v] until done
set tempo to (0) bpm
change tempo by (50)
wait (1) secs
change tempo by (-49)stop all sounds
play sound [carrot v] until done
set tempo to (0) bpm
set tempo to (30000) bpm
wait (1) secs
set tempo to (600) bpm
play drum ( v) for (0.2) beatsThose blocks are for midi instruments.
rest for () beats
play note ( v) for (0.5) beats
set instrument to ( v)
change tempo by ()
set tempo to (tempo) bpm
- footsocktoe
-
1000+ posts
Instead of stopping all sounds, how to stop a specific sound?
That is what Liam48D's solution does!I don't think the tempo affects sound assets. Nothing is wrong with mine.Your solution does not stop a sound in the middle of it playing. Either one wants the sound to loop over and over or one doesn't.
Given his condition that no other sounds playing can stop, I don't think what he wants is possible.
I know. I said Liam48D's solution was interesting. But as shown, his solution depends on sprite clicking and what OP wants is an automatic stop when the backdrop changes. Maybe I will play with it and see what I can come up with. It would be a handy ability to have.
- gdpr533f604550b2f20900645890
-
1000+ posts
Instead of stopping all sounds, how to stop a specific sound?
*Sigh* Lemme show you how to use Liam48D's solution. The sprite-clicking was just UI in the demonstration, and the solution itself is extensible. I know. I said Liam48D's solution was interesting. But as shown, his solution depends on sprite clicking and what OP wants is an automatic stop when the backdrop changes. Maybe I will play with it and see what I can come up with. It would be a handy ability to have.
define Sound (id) (sound) //Instantiate clone of sprite Sound
set [id v] to (id) //Local var
set [sound v] to (sound) //Local var
create clone of [myself v]
when I start as a clone //Clone plays sound
play sound (sound)
when backdrop switches to [foobar v] //What the OP wants
stopSound [1]
define stopSound (id) //Function to stop sound
set [cloneToStop v] to [1] //Specify the clone to delete
broadcast [stopSound v] and wait
when I receive [stopSound v]
if <(id ::variables) = (cloneToStop)> then //If the clone's ID matches, delete it
delete this clone
end
Last edited by gdpr533f604550b2f20900645890 (April 2, 2016 19:21:39)
- footsocktoe
-
1000+ posts
Instead of stopping all sounds, how to stop a specific sound?
*Sigh* Lemme show you how to use Liam48D's solution. The sprite-clicking was just UI in the demonstration, and the solution itself is extensible. I know. I said Liam48D's solution was interesting. But as shown, his solution depends on sprite clicking and what OP wants is an automatic stop when the backdrop changes. Maybe I will play with it and see what I can come up with. It would be a handy ability to have.define Sound (id) (sound) //Instantiate clone of sprite Sound
set [id v] to (id) //Local var
set [sound v] to (sound) //Local var
create clone of [myself v]
when I start as a clone //Clone plays sound
play sound (sound)
when backdrop switches to [foobar v] //What the OP wants
stopSound [1]
define stopSound (id) //Function to stop sound
set [cloneToStop v] to [1] //Specify the clone to delete
broadcast [stopSound v] and wait
when I receive [stopSound v]
if <(id) = (cloneToStop)> then //If the clone's ID matches, delete it
delete this clone
end
Good solution!

I was hoping you would do it instead of me. Issue resolved.

- gdpr533f604550b2f20900645890
-
1000+ posts
Instead of stopping all sounds, how to stop a specific sound?
Also, according to Liam's project, TheLogFather actually found the solution first.
- Discussion Forums
- » Help with Scripts
-
» Instead of stopping all sounds, how to stop a specific sound?