- This article is about the block. For more information about the value this block reports, see Volume (value).
Volume | |
volume | |
Category | Sound |
Type | Reporter |
Introduced in | 1.2 |
The Volume block is a Sound block and a reporter block. The block holds a Sprite's, clone's or the stage's volume. This block can be displayed as a Stage Monitor.
Example Uses
As this block holds how loud sounds, drums, and notes will be played, it is useful in music projects where they must sense how loud an instrument has been played.
Some common uses for the Volume block:
- Volume controls
when this sprite clicked repeat until <not <mouse down?>> point towards (mouse-pointer v) if <(direction) < [0]> then point in direction (0) else if <(direction) > [100]> then point in direction (100) else set volume to (direction)% end end say (join (volume) [%]) end say (join (volume) [%]) for (2) secs
- Loops that must stop once the volume is at a certain amount
repeat until <(volume) = [0]> change volume by (-10) end
- Sensing how loud something is being played
when gf clicked forever say (volume)
Workaround
- Main article: List of Block Workarounds
This block can be simply replicated with the following code:
([volume v] of (sprite v))
where "sprite" is the name of the wanted sprite.
It can also be replicated by using a variable to save the value:
define set volume to (number1)% set [volume v] to (number1) if <(volume::variables) < [0]> then set [volume v] to [0] end if <(volume::variables) > [100]> then set [volume v] to [100] end set volume to (volume::variables)% define change volume by (number1) set volume to ((volume::variables) + (number1))%::custom