再新建代码块之前 更改scratch-blocks代码 需要重新编译,
可以看这篇文章<blocks免编译>
首先找到目录scratch-gui-developsrclibmake-toolbox-xml.js
gui里面的代码块都在这里(扩展的除外)
const variables = function () {//关节变量
return `
<category
name="关节型变量"
id="variables"
colour="#ff1a39"
secondaryColour="#DB6E00"
>
<block type="data_variable" backgroundcolor="red">
<value name="DEGREES">
<shadow type="math_number">
<field name="NUM">15</field>
</shadow>
</value>
</block>
<block type="data_setvariableto">
<value name="DEGREES">
<shadow type="math_number">
<field name="NUM">15</field>
</shadow>
</value>
<value name="x">
<shadow id="movex" type="math_number">
<field name="NUM">0</field>
</shadow>
</value>
<value name="y">
<shadow id="movey" type="math_number">
<field name="NUM">0</field>
</shadow>
</value>
<value name="z">
<shadow id="movex" type="math_number">
<field name="NUM">10</field>
</shadow>
</value>
<value name="a">
<shadow id="movey" type="math_number">
<field name="NUM">9</field>
</shadow>
</value>
</block>
</category>
`;
};
再找到之前免编译的文件scratch-gui-developsrclibscratch-blocks-modifyblocks_svg.js
Blockly.Blocks['data_setvariableto'] = {
/**
* Block to set variable to a certain value
* @this Blockly.Block
*/
init: function () {
this.jsonInit({
"message0": "将变量 %1 X值设为 %2 Y值设为 %3 Z值设为 %4 A值设为 %5",
"args0": [
{
"type": "field_variable",
"name": "VARIABLE"
},
{
"type": "input_value",
"name": "x"
},
{
"type": "input_value",
"name": "y"
},
{
"type": "input_value",
"name": "z"
},
{
"type": "input_value",
"name": "a"
}
],
"category": Blockly.Categories.data,
"extensions": ["colours_data", "shape_statement"]
});
}
};
args0里面的name值一定与make-toolbox-xml.js里面的name值一样 否则会这样
![edf80fe6fb0361a1e27d2335ea0a1a6b.png](https://i-blog.csdnimg.cn/blog_migrate/ab242019fb6217ce48fb78e6c49f3755.png)
message0里面的汉字一定要从%1 开始 ;有几个%n, args0里面就有n个{ },
如果variables是新建的 要在下面添加:
const variablesXML = moveCategory('data') || variables(isStage, targetId);
const everything = [
xmlOpen,//不动
variablesXML, gap,//关节型变量
];
全部ok了效果就出来了
![c06560d8c404ec7519c8807f4ada5461.png](https://i-blog.csdnimg.cn/blog_migrate/bc0db57d27177251e5af134ae11d6644.png)
要想改变形状 可以看 《blocks的类型》
![14a82e221b3dfed2aedf718d564b203a.png](https://i-blog.csdnimg.cn/blog_migrate/d012d92eb15c5b741499107d6f3ef1f3.png)