(Redirected from Sound on/off Button)


Document.png Please expand this article or section. You can help by adding more information if you are an editor. More information might be found in a section of the talk page. (August 2018)
Note Warning: Loud sounds (such as screams and certain genres of music) can hurt the viewer's ears or even cause deafness; especially if the volume is set too high or the user is using head/earphones. When using such sounds, it is always wise to add a warning in the Notes and Credits or lower the volume of the audio if possible. Even so if it is too loud your project may be taken down by the Scratch Team.

A sound on/off button may be useful when making a game that has music or sound that can be muted or stopped.

To make a sound on/off button, one will need a sprite in the form of a switch. The switch must provide two costumes, one to represent when sound is on, and the other to represent when sound is off.

when gf clicked
switch costume to (sound-on v)

when this sprite clicked
next costume
if <(costume [number v]) = [2]> then //assuming the second costume is "off" and the first "on"
set volume to (0)% //if now off, turn off the volume
else
set volume to (100)% //if now on, turn on the volume
end

This script can be modified to allow the volume to be changed.


Here is another way to switch volumes, which only uses one block but has more complicated behaviour:

when this sprite clicked
set volume to (((((volume) / (100)) + (1)) mod (2))*(100))%

Note that this script switches between volume 0 and 100. To change the "on" volume replace the 100 with your volume

Note Note: When using these scripts, the sound will not pause and will keep playing silently. Due to this, when the sound resumes, it will not be in the same place as when it was stopped

See Also

Cookies help us deliver our services. By using our services, you agree to our use of cookies.