setChek and setPreviousStatement Details

27 views
Skip to first unread message

Rainbow Market

unread,
Jun 20, 2024, 1:28:44 PM (9 days ago) Jun 20
to Blockly
Dear Team,

please help me for blocks "setCheck", "setPreviousStatement" and "setNextStatement" how to handle,
this is my code, i am try to do main block inside one by one sub_block 1 to 4 but it's not working.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Custom Blockly Blocks</title>
    <!-- Load Blockly -->
    <script src="https://unpkg.com/blockly/blockly.min.js"></script>
    <style>
      body {
        font-family: sans-serif;
      }
      #blocklyDiv {
        height: 480px;
        width: 600px;
      }
    </style>
  </head>
  <body>
    <h1>Blockly Custom Blocks Example</h1>
    <div id="blocklyDiv"></div>
    <xml id="toolbox" style="display: none">
      <block type="main_block"></block>
      <block type="sub_block_1"></block>
      <block type="sub_block_2"></block>
      <block type="sub_block_3"></block>
      <block type="sub_block_4"></block>
    </xml>

    <script>
      Blockly.Blocks['main_block'] = {
        init: function() {
          this.appendDummyInput()
              .appendField("main block");
          this.appendStatementInput("NAME")
              .setCheck("sub_block_1");
          this.setColour(230);
          this.setTooltip("");
          this.setHelpUrl("");
        }
      };

      Blockly.Blocks['sub_block_1'] = {
        init: function() {
          this.appendDummyInput()
              .appendField("sub block 1");
          this.appendStatementInput("NAME")
              .setCheck(null);
          this.setPreviousStatement(true, null);
          this.setNextStatement(true, "sub_block_2");
          this.setColour(230);
          this.setTooltip("");
          this.setHelpUrl("");
        }
      };

      Blockly.Blocks['sub_block_2'] = {
        init: function() {
          this.appendDummyInput()
              .appendField("sub block 2");
          this.appendStatementInput("NAME")
              .setCheck(null);
          this.setPreviousStatement(true, "sub_block_1");
          this.setNextStatement(true, "sub_block_3");
          this.setColour(230);
          this.setTooltip("");
          this.setHelpUrl("");
        }
      };

      Blockly.Blocks['sub_block_3'] = {
        init: function() {
          this.appendDummyInput()
              .appendField("sub block 3");
          this.appendStatementInput("NAME")
              .setCheck(null);
          this.setPreviousStatement(true, "sub_block_2");
          this.setNextStatement(true, "sub_block_4");
          this.setColour(230);
          this.setTooltip("");
          this.setHelpUrl("");
        }
      };

      Blockly.Blocks['sub_block_4'] = {
        init: function() {
          this.appendDummyInput()
              .appendField("sub block 4");
          this.appendStatementInput("NAME")
              .setCheck(null);
          this.setPreviousStatement(true, "sub_block_3");
          this.setNextStatement(true, null);
          this.setColour(230);
          this.setTooltip("");
          this.setHelpUrl("");
        }
      };

      // Initialize Blockly
      const workspace = Blockly.inject('blocklyDiv', {
        toolbox: document.getElementById('toolbox')
      });
    </script>
  </body>
</html>

Regards,
Naveen S.

Mark Friedman

unread,
Jun 20, 2024, 6:35:00 PM (9 days ago) Jun 20
to blo...@googlegroups.com
Naveen,

  I am assuming that you want the various "sub" blocks to be allowed only in the order 1-4.  Given that, I believe that the only thing that you are missing in your code is the specification of the connection type for sub_block_1 in its call to setPreviousStatement. You specified it correctly for the other sub-blocks.

  Hope this helps.

-Mark


--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/blockly/b77cd14c-cc75-46d9-9498-aa5dc31faca8n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages