I have successfully made new variables, partly thanks to all of your help. And I've tried to be a good citizen and look carefully in the reference. No joy.
Here's what I want to do: when a user makes a new variable, I want to make a suitable "set" block appear in the workspace. As far as I can tell, that means making a new block of the right type and then setting the appropriate fields. In this case, (looking at an existing block) it appear there's one such field, a "VAR" field that contains an object with the id of the variable in question.
Here is my code, showing some other attempts; theName is the desired name of the variable.
const newVarResult = await this.workspace.createVariable(theName);
let newBlock = this.workspace.newBlock('variables_set');
//const idObject = {"id" : newVarResult.id_};
newBlock.moveBy(222,111); // maybe I have to move it??
// newBlock.setFieldValue(idObject, 'VAR'); // doesn't lik e this...
newBlock.setFieldValue(newVarResult.id_, 'VAR');
It runs. It makes an ID. The new variable name will appear in the menus on a set block if you pull it out of the toolbox. But nothing appears in the workspace as a result of this code. ("where" gives me 0, 0).
Any help is welcome, including to a demo or example that does something like this.
Thanks,
Tim