Skip to content

Commit

Permalink
Lily/SoundExpanded: fix "change project volume" block (#1423)
Browse files Browse the repository at this point in the history
It used to just always set the volume to 0. This fixes it.

This also makes the set volume block be clamped to 0-100 instead of
being wrapped around 0-199, which I think makes more sense and is
consistent with the vanilla set volume block. Though I'm not sure if it
wrapping around 199 instead of 100 (or 99) was a mistake or not, or if
it'll break projects.
  • Loading branch information
CST1229 committed Apr 24, 2024
1 parent dc6202a commit bca47b9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions extensions/Lily/SoundExpanded.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,15 +530,15 @@

setProjectVolume(args) {
const value = Scratch.Cast.toNumber(args.VALUE);
const newVolume = this._wrapClamp(value / 100, 0, 1);
const newVolume = Scratch.Cast.toNumber(Math.max(Math.min(value, 1), 0));
runtime.audioEngine.inputNode.gain.value = newVolume;
}

changeProjectVolume(args) {
const value = Scratch.Cast.toNumber(args.VALUE) / 100;
const volume = runtime.audioEngine.inputNode.gain.value;
const newVolume = Scratch.Cast.toNumber(
Math.min(Math.max(volume + value, 1), 0)
Math.max(Math.min(volume + value, 1), 0)
);
runtime.audioEngine.inputNode.gain.value = newVolume;
}
Expand Down

0 comments on commit bca47b9

Please sign in to comment.