volume

From PenguinMod Wiki
Volume
Jump to navigation Jump to search
volume
volume
Caption
Block Type Reporter Block
Category / Extension Sound
Status Who tf uses status

The volume block is a reporter block in the Sound category that reports the current volume of the sprite that the block is in. Volume is local, and can be shown as a stage monitor. The default volume for a sprite is the same as the default value of the set volume to ()% block, and the maximum volume, or 100. It originates from Scratch.

Workaround

This block can be worked around by using variables to save the current volume:

define set volume to (number1)%
set [volume v] to (number1)
set volume to (volume::variables)%
define change volume by (number1)
set volume to ((volume::variables) + (number1))%::custom

However, this workaround does not account for the fact that the volume must be in between 0 and 100, inclusive, which can be done using if statements:

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)%

Alternatively, the () of () sensing reporter can be used instead, by using the same sprite that the block is in as the 2nd dropdown by copying the block from another sprite to the sprite wanted, or by using a reporter block, or by using a variable to save the volume:

//1st workaround
([volume v] of (this sprite v))
([volume v] of ([this sprite]::operators))


//2nd workaround (variable saving volume)

//The following code goes in another sprite
when gf clicked
forever
set [vol v] to ([volume v] of (sprite wanted v))
end //this code

The value of the "vol" variable can then be accessed from another sprite.
This can also be done for the Stage. However, the workarounds involving the () of () sensing block do not work for clones, as it will always report the volume for the main sprite.