diff --git a/core/variables.js b/core/variables.js index fbd627f48..36cb36358 100644 --- a/core/variables.js +++ b/core/variables.js @@ -539,7 +539,13 @@ Blockly.Variables.getVariable = function(workspace, id, opt_name, opt_type) { if (!variable && potentialVariableMap) { variable = potentialVariableMap.getVariableById(id); } - } else if (opt_name) { + if (variable) { + return variable; + } + } + // If there was no ID, or there was an ID but it didn't match any variables, + // look up by name and type. + if (opt_name) { if (opt_type == undefined) { throw Error('Tried to look up a variable by name without a type'); }