Discuss Scratch

Staticstray
New to Scratch
9 posts

How can I make a Sound start on a backdrop and repeat until the backdrop changes?

I want each backdrop to have a different ambient sound, and to repeat, but to stop and change to another sound when the backdrop changes. My character will move from one backdrop to the next.

https://scratch.mit.edu/projects/378078783

here's my project for reference. Thank you for the help!
TheForceStudio
Scratcher
100+ posts

How can I make a Sound start on a backdrop and repeat until the backdrop changes?

I have good news for you, there is such a block as
when backdrop switches to [ v]

And you can use it for your own purposes!
when backdrop switches to [backdrop1 v]
stop all sounds
repeat until <not <(backdrop [name v]::looks) = [backdrop1]>>
play sound [backdrop1 ambient v] until done
end

when backdrop switches to [backdrop2 v]
stop all sounds
repeat until <not <(backdrop [name v]::looks) = [backdrop2]>>
play sound [backdrop2 ambient v] until done
end

(this code in backdrop)
Staticstray
New to Scratch
9 posts

How can I make a Sound start on a backdrop and repeat until the backdrop changes?

TheForceStudio wrote:

I have good news for you, there is such a block as
when backdrop switches to [ v]

And you can use it for your own purposes!
when backdrop switches to [backdrop1 v]
stop all sounds
repeat until <not <(backdrop [name v]::looks) = [backdrop1]>>
play sound [backdrop1 ambient v] until done
end

when backdrop switches to [backdrop2 v]
stop all sounds
repeat until <not <(backdrop [name v]::looks) = [backdrop2]>>
play sound [backdrop2 ambient v] until done
end

(this code in backdrop)

I've tried this same thing, but it doesn't seem to work. The sound won't start when the background changes.
fdreerf
Scratcher
1000+ posts

How can I make a Sound start on a backdrop and repeat until the backdrop changes?

forever
if <(backdrop #) = [1]> then
stop all sounds
repeat until <not <(backdrop #) =[1]>>
play sound [ v] until done
end
end
... // duplicate however many times you need
end
Generally, I find that these hat blocks seem to sometimes not work for whatever reason. I always use the forever if workarounds.
when [ v] key pressed
when this sprite clicked
when backdrop switches to [ v]
when [ v] > (10)

Hyped for MS-DOS 11.0
Staticstray
New to Scratch
9 posts

How can I make a Sound start on a backdrop and repeat until the backdrop changes?

fdreerf wrote:

forever
if <(backdrop #) = [1]> then
stop all sounds
repeat until <not <(backdrop #) =[1]>>
play sound [ v] until done
end
end
... // duplicate however many times you need
end
Generally, I find that these hat blocks seem to sometimes not work for whatever reason. I always use the forever if workarounds.
when [ v] key pressed
when this sprite clicked
when backdrop switches to [ v]
when [ v] > (10)

This works better, but the sounds still won't stop when the backdrop changes. Is there a way to stop them immediately without using the Stop All sounds block? There are other sounds I don't want to stop when backdrops are switched.
imfh
Scratcher
1000+ posts

How can I make a Sound start on a backdrop and repeat until the backdrop changes?

I think you can do something like the below to stop a sound and start a new one. If a script is running under when I receive when it is broadcasted, the script will stop and restart. I think the sound will stop with the script, but I could be wrong.

when I receive [Restart sound v]
forever
if <(backdrop [number v]::looks) = [1]> then
play sound [backdrop1 v] until done
else
if <(backdrop [number v]::looks) = [2]> then
play sound [backdrop2 v] until done
else
...
end
end
end

Scratch to Pygame converter: https://scratch.mit.edu/discuss/topic/600562/
fdreerf
Scratcher
1000+ posts

How can I make a Sound start on a backdrop and repeat until the backdrop changes?

Staticstray wrote:

This works better, but the sounds still won't stop when the backdrop changes. Is there a way to stop them immediately without using the Stop All sounds block? There are other sounds I don't want to stop when backdrops are switched.
I'm afraid not.

Hyped for MS-DOS 11.0
Oumuamua
Scratcher
1000+ posts

How can I make a Sound start on a backdrop and repeat until the backdrop changes?

fdreerf wrote:

Staticstray wrote:

This works better, but the sounds still won't stop when the backdrop changes. Is there a way to stop them immediately without using the Stop All sounds block? There are other sounds I don't want to stop when backdrops are switched.
I'm afraid not.

Yes, there is a way, move all sounds into a new sprite, when you want to play a specific sound create a clone of such sprite and make it play that sound, to stop the sound you just delete the clone.


Oumuamua
Scratcher
1000+ posts

How can I make a Sound start on a backdrop and repeat until the backdrop changes?

FoofJr
Scratcher
100+ posts

How can I make a Sound start on a backdrop and repeat until the backdrop changes?

fdreerf wrote:

forever
if <(backdrop #) = [1]> then
stop all sounds
repeat until <not <(backdrop #) =[1]>>
play sound [ v] until done
end
end
... // duplicate however many times you need
end
Generally, I find that these hat blocks seem to sometimes not work for whatever reason. I always use the forever if workarounds.
when [ v] key pressed
when this sprite clicked
when backdrop switches to [ v]
when [ v] > (10)


Agreed. Even with the when key pressed hat blocks, they almost never work correctly.

Why hello there! Wonder why you are checking out my signature. While you're at it, why not check out my Gradient generator?
Staticstray
New to Scratch
9 posts

How can I make a Sound start on a backdrop and repeat until the backdrop changes?

Oumuamua wrote:

fdreerf wrote:

Staticstray wrote:

This works better, but the sounds still won't stop when the backdrop changes. Is there a way to stop them immediately without using the Stop All sounds block? There are other sounds I don't want to stop when backdrops are switched.
I'm afraid not.

Yes, there is a way, move all sounds into a new sprite, when you want to play a specific sound create a clone of such sprite and make it play that sound, to stop the sound you just delete the clone.

This works if you only have one sound to stop, but it has the same problems as before when switching from one sound to another. Thank you for the idea anyway though
Oumuamua
Scratcher
1000+ posts

How can I make a Sound start on a backdrop and repeat until the backdrop changes?

Staticstray wrote:

Oumuamua wrote:

Yes, there is a way, move all sounds into a new sprite, when you want to play a specific sound create a clone of such sprite and make it play that sound, to stop the sound you just delete the clone.

This works if you only have one sound to stop, but it has the same problems as before when switching from one sound to another. Thank you for the idea anyway though


I´d say that you need to practice scratching a bit more….


Staticstray
New to Scratch
9 posts

How can I make a Sound start on a backdrop and repeat until the backdrop changes?

Oumuamua wrote:

Staticstray wrote:

Oumuamua wrote:

Yes, there is a way, move all sounds into a new sprite, when you want to play a specific sound create a clone of such sprite and make it play that sound, to stop the sound you just delete the clone.

This works if you only have one sound to stop, but it has the same problems as before when switching from one sound to another. Thank you for the idea anyway though


I´d say that you need to practice scratching a bit more….

Im trying but i'm just not sure it will work for my project.

Last edited by Staticstray (March 25, 2020 19:22:21)

Oumuamua
Scratcher
1000+ posts

How can I make a Sound start on a backdrop and repeat until the backdrop changes?

It is OK, do you speak Spanish fluently? I am askig because it is too much stuff to explain and i have very little skill writing and speaking English, and dealing with clones require full understanding cause some times it is a tricki thing. Just wait to other scratcher able to explain. You keep scratching. Greetings.


ipaddude
Scratcher
100+ posts

How can I make a Sound start on a backdrop and repeat until the backdrop changes?

make a sprite for the sound and insert this loop:

forever
if <(backdrop name) = [your backdrop name... duh]> then
set volume to (100) %
else
set volume to (0) %
end
end
and then just put this in
forever
play sound [sound v] until done
end

however the sound will not restart and continues playing after muted.

i sure hope osu lazer will support gnu hurd

arch btw ͡° ͜ʖ ͡°
test
abcdefghijklmnopqr20
Scratcher
7 posts

How can I make a Sound start on a backdrop and repeat until the backdrop changes?

put this code in to where you want
switch backdrop to [backdropname]
then put this one in too.
when backdrop switches to [backdropname v]
repeat until <not <(backdrop #) = [1]>>
play sound [yoursound v] until done
end

if the “when backdrop switches to” hat block does'nt work, try to replace the
 when backdrop switches to [backdropname v] 
hat block with the
when green flag clicked
hat block.

Hi, im Tristan! I make games(recently multiplayer) on scratch, and tinker with JavaScript, HTML5, and CSS(a litle bit)
————————————————————————-
Check out my new game, ☁️ Tag!
Chary500
Scratcher
4 posts

How can I make a Sound start on a backdrop and repeat until the backdrop changes?

Check this project out and it will solve your problem https://scratch.mit.edu/projects/572137294
And when you get to it press see inside
deck26
Scratcher
1000+ posts

How can I make a Sound start on a backdrop and repeat until the backdrop changes?

Chary500 wrote:

Check this project out and it will solve your problem https://scratch.mit.edu/projects/572137294
And when you get to it press see inside
Please try not to necropost. The topic is over a year old so is presumably resolved.

Powered by DjangoBB