Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Need help playing a sound in a loop when a certain key is pressed.
- Alexcamostyle
- Scratcher
81 posts
Need help playing a sound in a loop when a certain key is pressed.
I'm making a game that involves a jetpack, and I want to play this looped sound when the jackpack is active.
I have something along the lines of this:
The problem is, it's playing the sound OVER and over again REALLY fast. So it ends up sounding like a crazed robot heartbeat. Is there a script that can play a looped sound only while the arrow key is pressed, and stop playing the sound immediately if it's not?
Thanks!
I have something along the lines of this:
when green flag clicked
forever
if <key [right arrow] pressed?> then
play sound [ v]
end
The problem is, it's playing the sound OVER and over again REALLY fast. So it ends up sounding like a crazed robot heartbeat. Is there a script that can play a looped sound only while the arrow key is pressed, and stop playing the sound immediately if it's not?
Thanks!
Last edited by Alexcamostyle (Sept. 26, 2014 18:03:29)
- stickfiregames
- Scratcher
1000+ posts
Need help playing a sound in a loop when a certain key is pressed.
Change
Unfortunately you can't stop and resume a sound,so the sound will play to the end of the current loop when you release the right arrow.
play sound [ v]to
play sound [ v] until done
Unfortunately you can't stop and resume a sound,so the sound will play to the end of the current loop when you release the right arrow.
- stickfiregames
- Scratcher
1000+ posts
Need help playing a sound in a loop when a certain key is pressed.
Actually, you could make it stop immediately if you have two scripts:
When it restarts playing it will start from the beginning.
when gf clicked
forever
if <key [right arrow v] pressed?> then
play sound [ v] until done
end
when gf clicked
forever
if <not <key [right arrow v] pressed?>> then
stop all sounds
end
When it restarts playing it will start from the beginning.
- Alexcamostyle
- Scratcher
81 posts
Need help playing a sound in a loop when a certain key is pressed.
Actually, you could make it stop immediately if you have two scripts:when gf clicked
forever
if <key [right arrow v] pressed?> then
play sound [ v] until done
end
when gf clicked
forever
if <not <key [right arrow v] pressed?>> then
stop all sounds
end
When it restarts playing it will start from the beginning.
Thanks! It's still being SUPER glitchy, though. So I think I'm gonna keep the game silent besides the music. In space you can't hear sound anyway.
Last edited by Alexcamostyle (Sept. 27, 2014 01:36:32)
- Discussion Forums
- » Help with Scripts
- » Need help playing a sound in a loop when a certain key is pressed.