stopping songs?
id: 749817
category: Help with Scripts
posts: 4
subnautica_subzero
loading
how do I stop a song mid-way with using the “play until done” script?
Malicondi
loading
you can have a seperate script to use either of these blocks:
stop all soundsthis will stop the sound. Hope this helps!
stop [other scripts in sprite v]
NuclearPhysics0
loading
Are you talking about pausing/unpausing? If you're not, you can just use “stop all sounds” combined with “stop other scripts in this sprite”, but if you are talking about pausing/unpausing, then here are a few methods:
Method 1: This is probably the easiest method, but also the least efficient one. It slows the song down by 8 times, but doesn't completely pause it. However, if the person playing it unpauses it quickly after pausing it, then it may seem like it was paused. Here's the code:
Method 2: This method stops the sound entirely, but tracks where the sound left off. It then plays the song, muted, as fast as possible until the sound reaches the point where it left off, then sets it to normal. The code looks like the following:
So, although this code is long, basically, delta is the change in time per frame. I don't want to get into detail, so if you want to know more, just know that the max change in speed is setting the pitch to 360, and that speeds it up by 8 times. Now, knowing that, if you want, you can study the code above in more detail. However, if you don't want to do that, just copy it and put it in the project. I do highly recommend studying the code, though.
Method 1: This is probably the easiest method, but also the least efficient one. It slows the song down by 8 times, but doesn't completely pause it. However, if the person playing it unpauses it quickly after pausing it, then it may seem like it was paused. Here's the code:
when I receive [Pause v]Now, the next method is more complex and takes longer for both you and the user, but it is FAR more efficient.
set [pitch v] effect to (-360) :: sound
set volume to (0) %
when I receive [Resume v]
set [pitch v] effect to (0) :: sound
set volume to (100) %
Method 2: This method stops the sound entirely, but tracks where the sound left off. It then plays the song, muted, as fast as possible until the sound reaches the point where it left off, then sets it to normal. The code looks like the following:
when green flag clicked
set [time v] to (0)
set [delta v] to (0)
set [last timer v] to (timer)
forever
set [delta v] to ((timer)-(last timer))
set [last timer v] to (timer)
if <unpaused :: operators> then
change [time v] by (delta)
end
if <condition to pause song :: operators> then
stop all sounds
stop [other scripts in sprite v]
broadcast [Pause v]
end
end
when I receive [Pause v]
set volume to (0) %
when I receive [Unpause v]
set [unpause timer v] to (0)
broadcast [Unpause 2 v]
play sound [whatever song v] until done
when I receive [Unpause 2 v]
set [pitch v] effect to (360) :: sound
set [unpause timer v] to (0)
repeat until <not <(time) < (unpause timer)>>
change [unpause timer v] by ((delta) * (8))
end
set volume to (100) %
So, although this code is long, basically, delta is the change in time per frame. I don't want to get into detail, so if you want to know more, just know that the max change in speed is setting the pitch to 360, and that speeds it up by 8 times. Now, knowing that, if you want, you can study the code above in more detail. However, if you don't want to do that, just copy it and put it in the project. I do highly recommend studying the code, though.
subnautica_subzero
loading
wow, thanks for all of this. This will be a big help.