Index2.workspace.registerToolboxCategoryCallback("CUSTOM_VARIABLE", () => {
let list: any[] = [];
list.push(
{
"kind": "button",
"text": "A button",
"callbackKey": "yourCallbackKey"
},
);
Index2.workspace.getAllVariables().forEach((item) => {
list.push({
"type": item.name,
"message0": "%1",
"args0": [
{ // Beginning of the field variable dropdown
"type": "field_variable",
"name": "VAR", // Static name of the field
"variable": item.name // Given at runtime
} // End of the field variable dropdown
],
"output": null, // Null means the return value can be of any type
})
})
return list;
});
Index2.workspace.registerButtonCallback("yourCallbackKey", (button) => {
Blockly.Variables.createVariableButtonHandler(button.getTargetWorkspace(), null);
});
Index2.workspace.getAllVariables().forEach((item) => {
javascriptGenerator.forBlock[item.name] = (block: Blockly.Block, generator: JavascriptGenerator): any => {
block; generator;
return item.name;
};
});