Hello,
I'm looking to build a blockly-phaser environment similar to Scratch
I'm stuck on variables, I want full control over the variables toolbox category, but I cannot seem to find a way to create a block per variable similar to how Scratch does.
The block type `variables_get` has a dropdown, but I'd rather have multiple copies of that with a label and a pre-selected variable instead of the drop down.
My attempt:
Block definition JSON:
type: 'variable_get_custom',
message0: '%1',
args0: [
{
type: 'input_dummy',
name: 'VAR',
}
],
output: null
Javascript:
(block, generator) => {
const varName = block.getFieldValue('VAR')
return [`${varName}`, Order.NONE]
}
Adding the blocks to the toolbox:
workspace.getAllVariableNames().forEach((x) => {
variableItems.push({
kind: 'block',
type: 'variable_get_custom',
fields: {
"VAR": x
}
})
})
Results in visually what I want:
But when I drag them out they go blank and the javascript output is "false"
function onGameStart () {
if (false) {
}
}
I'm not sure if I'm approaching this correctly.
The built-in variable blocks auto-update when a variable is deleted so I don't even know if I can have custom blocks for variables that are also reactive to changes in the workspace's variables... Any advice on what I can do?
Also, extra question, does Scratch use multiple blockly workspaces? Like, one for each sprite and backdrop? I'm approaching this project with the idea I'll need a container that shares information between multiple workspaces that get hidden and shown
Thanks for taking the time to read my post
-Chris