I am working on a project that paints Objects from Blockly Code Blocks. Therefore a code string is generated that is evaluated in the function below. In the code run with the eval function, all created objects are stored in an array (objects). My problem is that the code is not completely evaluated before alert(objects.length) can work with the updated objects array (so it alerts zero as I have reset the array before). So the alert should wait for the eval function. Can you help me how to solve this problem?
function paintFromCode() {
slideTo('konva_box');
setTimeout(function(){
deleteObjects();
let code = Blockly.JavaScript.workspaceToCode(workspace);
try {
code = "let t = 0;" + code;
eval(code);
} catch (e) {
alert(e);
}
layer.add(pospanel);
alert(objects.length);
}, 1000);
}
Part of the function where the code is created:
let code = "setTimeout( function() {" +
"objects['" + text_identifier.toUpperCase() + "'] = new Konva.Circle({x: 50, y: 100, radius: 50, fill: '#00ff00'});" +
"layer.add(objects['" + text_identifier.toUpperCase() + "']);" +
"layer.draw();" +
"}, speed * t);" +
"t = t + 1;";
return code;