This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2013-03-22 20:50:31

m4tthaynes
New Scratcher
Registered: 2013-03-22
Posts: 2

Press and Release

Is it possible to create a script that basically uses 1 button for to functions. So for instance. Can I have a script that says "If space is pressed and held play sound x. If space is released stop all sound?"

Offline

 

#2 2013-03-22 20:57:03

Harald
New Scratcher
Registered: 2013-03-05
Posts: 34

Re: Press and Release

That is indeed possible.


when gf clicked

forever  

if <key [space v] pressed?>

play sound [X v] until done

else

stop all sounds

end

end

Offline

 

#3 2013-03-22 21:00:33

Harald
New Scratcher
Registered: 2013-03-05
Posts: 34

Re: Press and Release

Another way to do it is to have one block constantly play a sound like this:


when gf clicked

forever  

play sound [X v] until done

end

And then have another one to adjust the volume. Then you can instantly turn it on and off.


when gf clicked

forever  

if <key [space v] pressed?>

set volume to (100)%

else

set volume to (0)%

end

end

Offline

 

#4 2013-03-22 21:03:43

m4tthaynes
New Scratcher
Registered: 2013-03-22
Posts: 2

Re: Press and Release

Thanks I think the first solution is exactly what I'm looking for!!!

Offline

 

#5 2013-03-22 21:10:50

Harald
New Scratcher
Registered: 2013-03-05
Posts: 34

Re: Press and Release

The first solution isn't very good if it's a long sound that is being played though, since it will not mute it until the sound is done playing. So if you press space, and release it, the sound will keep playing until it's finished.
The second one allows your sound to keep playing, but you decide when you want to hear it or not.

Offline

 

Board footer