variablesgithubjdeveloperblockly

Blockly How to create a Variable to the workspace (developer variable)


I want to create a Developer Variable to the workspace in Blockly, but I cannot find the necessary function/method.

I do not want to create the variable over a button. The variable should be included even if there is no block in the workspace.

With these two functions I can get the already created variables:

var variables = workspace.getAllVariables();
var dev_var = Blockly.Variables.allDeveloperVariables(workspace);

But what is the setting function?


Solution

  • Developer variables are variables that will never be visible to the user, but will exist in the generated code. If that's what you're looking for: there's no API for it, but here are some things you can do.

    On the other hand, if what you want is a user-visible variable that always shows up in the toolbox, without the user creating it, you should call yourWorkspace.createVariable('variable_name').