Add lower limit argument to device_random (#990)

* Add lower limit argument to device_random

* Better checking
This commit is contained in:
Richard Knoll 2018-07-30 14:13:28 -07:00 committed by GitHub
parent 64a25f5f61
commit 8dff9e3d09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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<pxt.editor.ExtensionResult> {