Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Use one key to toggle a loop on and off
- bhughesbhs
-
3 posts
Use one key to toggle a loop on and off
Hi world,
I'm looking to create a code to use to create basic launchpad for music loops. I'd like to trigger an audio file/loop by pressing one key, have the playback continually loop itself until the same key is pressed again. Any suggestions?
I'm looking to create a code to use to create basic launchpad for music loops. I'd like to trigger an audio file/loop by pressing one key, have the playback continually loop itself until the same key is pressed again. Any suggestions?
- gor-dee
-
1000+ posts
Use one key to toggle a loop on and off
I think you will have to use clones, otherwise the “stop all sounds” block will stop ALL sounds. If you have a sprite for each sound and have
that might work……………….
when green flag clicked
set [sound] to [off ]
forever
wait until <key [key] pressed?>
if <[sound] = [off ]> then
create clone of [myself]
set [sound] to [on ]
if <[sound] = [ on]> then
set [sound] to [ off]
delete this clone
wait until <not <key [ key] pressed?>>
end
end
end
when I start as a clone
forever
play sound [ v] until done
end
that might work……………….
- gor-dee
-
1000+ posts
Use one key to toggle a loop on and off
wait until not key pressed should be right at the end of the forever loop I think you will have to use clones, otherwise the “stop all sounds” block will stop ALL sounds. If you have a sprite for each sound and havewhen green flag clicked
set [sound] to [off ]
forever
wait until <key [key] pressed?>
if <[sound] = [off ]> then
create clone of [myself]
set [sound] to [on ]
if <[sound] = [ on]> then
set [sound] to [ off]
delete this clone
wait until <not <key [ key] pressed?>>
end
end
endwhen I start as a clone
forever
play sound [ v] until done
end
that might work……………….
- footsocktoe
-
1000+ posts
Use one key to toggle a loop on and off
Hi world,
I'm looking to create a code to use to create basic launchpad for music loops. I'd like to trigger an audio file/loop by pressing one key, have the playback continually loop itself until the same key is pressed again. Any suggestions?
If you don't mind the loop finishing itself before it stops, you can create a variable called “play” and use…
set [play] to [1 ]This works because the variable “play” is being toggled between -1 and +1 on alternate clicks on the sprite.
when this sprite clicked
set [play] to ((play) * (-1))
repeat until <(play) > [0 ]>
play sound [ v] until done
end
Last edited by footsocktoe (Feb. 4, 2016 10:34:40)
- minecrafterisaac
-
7 posts
Use one key to toggle a loop on and off
i dont think so I think you will have to use clones, otherwise the “stop all sounds” block will stop ALL sounds. If you have a sprite for each sound and havewhen green flag clicked
set [sound] to [off ]
forever
wait until <key [key] pressed?>
if <[sound] = [off ]> then
create clone of [myself]
set [sound] to [on ]
if <[sound] = [ on]> then
set [sound] to [ off]
delete this clone
wait until <not <key [ key] pressed?>>
end
end
endwhen I start as a clone
forever
play sound [ v] until done
end
that might work……………….
- deck26
-
1000+ posts
Use one key to toggle a loop on and off
Why comment on a 4 year old topic?i dont think so I think you will have to use clones, otherwise the “stop all sounds” block will stop ALL sounds. If you have a sprite for each sound and havewhen green flag clicked
set [sound] to [off ]
forever
wait until <key [key] pressed?>
if <[sound] = [off ]> then
create clone of [myself]
set [sound] to [on ]
if <[sound] = [ on]> then
set [sound] to [ off]
delete this clone
wait until <not <key [ key] pressed?>>
end
end
endwhen I start as a clone
forever
play sound [ v] until done
end
that might work……………….
- numbercruncher324
-
29 posts
Use one key to toggle a loop on and off
I think you will have to use clones, otherwise the “stop all sounds” block will stop ALL sounds. If you have a sprite for each sound and havewhen green flag clicked
set [sound] to [off ]
forever
wait until <key [key] pressed?>
if <[sound] = [off ]> then
create clone of [myself]
set [sound] to [on ]
if <[sound] = [ on]> then
set [sound] to [ off]
delete this clone
wait until <not <key [ key] pressed?>>
end
end
endwhen I start as a clone
forever
play sound [ v] until done
end
that might work……………….
well I want a modern day one so can you please give me a modern ver. tutorial, if you already have one, please bring me to it
- numbercruncher324
-
29 posts
Use one key to toggle a loop on and off
I think you will have to use clones, otherwise the “stop all sounds” block will stop ALL sounds. If you have a sprite for each sound and havewhen green flag clicked
set [sound] to [off ]
forever
wait until <key [key] pressed?>
if <[sound] = [off ]> then
create clone of [myself]
set [sound] to [on ]
if <[sound] = [ on]> then
set [sound] to [ off]
delete this clone
wait until <not <key [ key] pressed?>>
end
end
endwhen I start as a clone
forever
play sound [ v] until done
end
that might work……………….
also that is very confusing because LOOK AT THE BOTTOM OF THE FIRST GROUP OF BLOCKS (STRING)
Last edited by numbercruncher324 (Dec. 28, 2024 18:01:43)
- Discussion Forums
- » Help with Scripts
-
» Use one key to toggle a loop on and off