loopsblockly

Blockly repeat block not working with both custom block and predefined blocks


I'm working on an Angular project using Blockly and Phaser but repeat block is not working. Here is a small test to print aa 3 times.

enter image description here

But I received this error:

JavaScript error message

Here is the code used:

 <block type="controls_repeat_ext">
     <value name="TIMES">
         <shadow type="math_number">
             <field name="NUM">3</field>
         </shadow>
     </value>
 </block>
 //and for the function 
  
 run.on(event.POINTER_DOWN ,(image) => {
     eval(document.getElementById('code').innerHTML);
     console.log("running" )
 });

What should I add to make this repeat work?


Solution

  • i just solved the problem by adding this code:

    (Blockly as any).JavaScript.addReservedWords('div2');
            var code = (Blockly as any).JavaScript.workspaceToCode();
            try {
              eval(code);
            } catch (e) {
              alert(e);
            }