diff --git a/src/blocks/scratch3_event.js b/src/blocks/scratch3_event.js index 3b4050b62..5ee2fab1d 100644 --- a/src/blocks/scratch3_event.js +++ b/src/blocks/scratch3_event.js @@ -55,27 +55,9 @@ class Scratch3EventBlocks { return false; } - /** - * Helper function to process broadcast block input (whether it's - * input from the dropdown menu or from a plugged in input block) - * @param {object} args The given arguments for the broadcast blocks - * @param {object} util The utility associated with this block. - * @return {?Variable} The broadcast message variable that matches - * the provided input. - */ - processBroadcastInput_ (args, util) { - let broadcastInput; - if (args.BROADCAST_OPTION) { - broadcastInput = util.runtime.getTargetForStage().lookupBroadcastMsg( - args.BROADCAST_OPTION.id, args.BROADCAST_OPTION.name); - } else { - broadcastInput = util.runtime.getTargetForStage().lookupBroadcastByInputValue(args.BROADCAST_INPUT.name); - } - return broadcastInput; - } - broadcast (args, util) { - const broadcastVar = this.processBroadcastInput_(args, util); + const broadcastVar = util.runtime.getTargetForStage().lookupBroadcastMsg( + args.BROADCAST_OPTION.id, args.BROADCAST_OPTION.name); if (broadcastVar) { const broadcastOption = broadcastVar.name; util.startHats('event_whenbroadcastreceived', { @@ -85,7 +67,8 @@ class Scratch3EventBlocks { } broadcastAndWait (args, util) { - const broadcastVar = this.processBroadcastInput_(args, util); + const broadcastVar = util.runtime.getTargetForStage().lookupBroadcastMsg( + args.BROADCAST_OPTION.id, args.BROADCAST_OPTION.name); if (broadcastVar) { const broadcastOption = broadcastVar.name; // Have we run before, starting threads? diff --git a/src/engine/execute.js b/src/engine/execute.js index a4b9404d8..13742ec76 100644 --- a/src/engine/execute.js +++ b/src/engine/execute.js @@ -217,9 +217,6 @@ const execute = function (sequencer, thread) { const broadcastInput = inputs[inputName]; // Check if something is plugged into the broadcast block, or // if the shadow dropdown menu is being used. - // Differentiate between these two cases by giving argValues - // a 'BROADCAST_INPUT' field or a 'BROADCAST_OPTION' field - // respectively. if (broadcastInput.block === broadcastInput.shadow) { // Shadow dropdown menu is being used. // Get the appropriate information out of it. @@ -232,7 +229,7 @@ const execute = function (sequencer, thread) { } else { // Something is plugged into the broadcast input. // Cast it to a string. We don't need an id here. - argValues.BROADCAST_INPUT = { + argValues.BROADCAST_OPTION = { name: cast.toString(inputValue) }; } diff --git a/src/engine/target.js b/src/engine/target.js index 480b1e83c..9861c455d 100644 --- a/src/engine/target.js +++ b/src/engine/target.js @@ -98,12 +98,19 @@ class Target extends EventEmitter { * if it exists. * @param {string} id Id of the variable. * @param {string} name Name of the variable. - * @return {!Variable} Variable object. + * @return {?Variable} Variable object. */ lookupBroadcastMsg (id, name) { - const broadcastMsg = this.lookupVariableById(id); + let broadcastMsg; + if (id) { + broadcastMsg = this.lookupVariableById(id); + } else if (name) { + broadcastMsg = this.lookupBroadcastByInputValue(name); + } else { + log.error('Cannot find broadcast message if neither id nor name are provided.'); + } if (broadcastMsg) { - if (broadcastMsg.name !== name) { + if (name && (broadcastMsg.name.toLowerCase() !== name.toLowerCase())) { log.error(`Found broadcast message with id: ${id}, but` + `its name, ${broadcastMsg.name} did not match expected name ${name}.`); }