From 8dff9e3d09f944ca593f826345263921c0b3f33c Mon Sep 17 00:00:00 2001 From: Richard Knoll Date: Mon, 30 Jul 2018 14:13:28 -0700 Subject: [PATCH] Add lower limit argument to device_random (#990) * Add lower limit argument to device_random * Better checking --- editor/extension.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/editor/extension.ts b/editor/extension.ts index c3bfc43e..a10a2847 100644 --- a/editor/extension.ts +++ b/editor/extension.ts @@ -593,6 +593,29 @@ namespace pxt.editor { } } }) + + + // device_random now refers to randomRange() so we need to add the missing lower bound argument + U.toArray(dom.querySelectorAll("block[type=device_random]")) + .forEach(node => { + for (let i = 0; i < node.children.length; i++) { + const child = node.children.item(i); + if (child.tagName === "value" && child.getAttribute("name") === "min") { + return; + } + } + const v = node.ownerDocument.createElement("value"); + const s = node.ownerDocument.createElement("shadow"); + const f = node.ownerDocument.createElement("field"); + + v.setAttribute("name", "min"); + v.appendChild(s); + s.setAttribute("type", "math_number"); + s.appendChild(f); + f.setAttribute("name", "NUM"); + f.textContent = "0"; + node.appendChild(v); + }); } initExtensionsAsync = function (opts: pxt.editor.ExtensionOptions): Promise {