diff --git a/src/blocks/scratch3_event.js b/src/blocks/scratch3_event.js index 37a254467..4da1dfae3 100644 --- a/src/blocks/scratch3_event.js +++ b/src/blocks/scratch3_event.js @@ -69,9 +69,11 @@ class Scratch3EventBlocks { hatGreaterThanPredicate (args, util) { const option = Cast.toString(args.WHENGREATERTHANMENU).toLowerCase(); const value = Cast.toNumber(args.VALUE); - // @todo: Other cases :) - if (option === 'timer') { + switch (option) { + case 'timer': return util.ioQuery('clock', 'projectTimer') > value; + case 'loudness': + return this.runtime.audioEngine && this.runtime.audioEngine.getLoudness() > value; } return false; } diff --git a/test/unit/blocks_event.js b/test/unit/blocks_event.js index 672ea332c..0cdc58e54 100644 --- a/test/unit/blocks_event.js +++ b/test/unit/blocks_event.js @@ -96,3 +96,17 @@ test('#760 - broadcastAndWait', t => { t.end(); }); + +test('When > hat - loudness', t => { + const rt = new Runtime(); + rt.audioEngine = {getLoudness: () => 10}; + const e = new Event(rt); + const args = { + WHENGREATERTHANMENU: 'LOUDNESS', + VALUE: '11' + }; + t.equal(e.hatGreaterThanPredicate(args), false); + args.VALUE = '5'; + t.equal(e.hatGreaterThanPredicate(args), true); + t.end(); +});