Admiration

Hello, i'm making a sprite which plays music if you hold down the space key, but i want the music to loop, so if i put in a
play sound [ v] until done
and release the space key, it won't stop, since i put a
stop all sounds
block in the code.

Here's the full code below:

when [space v] key pressed
switch costume to [costumehere v]
if <[costume #] = [2]>() then 
play sound [musichere v] until done



else

wait until <not <key [space v] pressed?>>
switch costume to [startcostume v]
stop all sounds

I'm still a bit new to posting, sorry if the code is jumbled.

kaylorb

try adding a different script that goes like this.

when green flag clicked 
forever
wait until <key [space] pressed?>
wait until <not <key [space] pressed?>>
stop all sounds
end
__________________________________________________________________
Have you seen my latest game?
https://scratch.mit.edu/projects/320513958/
Click the link above!

a-jar-of-tuna

If youre looking to pause it, it's near impossible; even if your code did run the song would restart every time you lifted up the space bar.
But anyway, it'll still work but just restart it completely (if that's what you want):
when [space v] key pressed
switch costume to [newcostume v]
repeat until <not <key [space v] pressed?>>
play sound [music v] until done
end
stop all sounds
switch costume to [startcostume v]
The problem with yours is the if/else - you're not actually changing costume so the else never runs.

codeman1044

A little trick that I know that almost works perfectly is this:
when [space v] key pressed
set [Paused v] to (((Paused)+(1)) mod (2))
if <(Paused)=(0)> then
set [pitch v] effect to (0)::sound
set volume to (100) %
else
set [pitch v] effect to ((0)-((1)/(0)))::sound
set volume to (0) %
when gf clicked
forever
play sound [ v] until done
This will set the pitch effect to negative infinity. The lower the pitch of the music, the slower it plays. It still plays, which is why the volume block is there.

a-jar-of-tuna

codeman1044 wrote:

A little trick that I know that almost works perfectly is this:
when [space v] key pressed
set [Paused v] to (((Paused)+(1)) mod (2))
if <(Paused)=(0)> then
set [pitch v] effect to (0)::sound
set volume to (100) %
else
set [pitch v] effect to ((0)-((1)/(0)))::sound
set volume to (0) %
when gf clicked
forever
play sound [ v] until done
This will set the pitch effect to negative infinity. The lower the pitch of the music, the slower it plays. It still plays, which is why the volume block is there.
Wow, that's really cool to know!