array set

This commit is contained in:
sussy layers dev 2023-11-28 15:42:32 +00:00 committed by GitHub
commit 5152fa6fee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View file

@ -79,6 +79,7 @@
<block type="json_tostring" />
<sep gap="64"></sep>
<block type="json_arrayinsert" />
<block type="json_arrayset" />
<sep gap="48"></sep>
<block type="json_arrayget" />
<block type="json_arraylength" />

View file

@ -82,6 +82,35 @@ function register() {
return [`(${X || "[]"}.push(${Y || '""'}))`, javascriptGenerator.ORDER_ATOMIC];
})
// set
registerBlock(`${categoryPrefix}arrayset`, {
message0: 'set %1 to %2 in %3',
args0: [
{
"type": "input_value",
"name": "X",
"check": "Number"
},
{
"type": "input_value",
"name": "Y",
},
{
"type": "input_value",
"name": "Z",
"check": "JSONArray"
},
],
output: "JSONArray",
inputsInline: true,
colour: categoryColor
}, (block) => {
const X = javascriptGenerator.valueToCode(block, 'X', javascriptGenerator.ORDER_ATOMIC);
const Y = javascriptGenerator.valueToCode(block, 'Y', javascriptGenerator.ORDER_ATOMIC);
const Z = javascriptGenerator.valueToCode(block, 'Z', javascriptGenerator.ORDER_ATOMIC);
return [`(() => { var z = ${Z}; z[${X}] = ${Y}; return z })()`, javascriptGenerator.ORDER_ATOMIC];
})
// get
registerBlock(`${categoryPrefix}arrayget`, {
message0: 'get %1 from array %2',