How the set twor shadow blocks in statement input in scratch junior

246 views
Skip to first unread message

Vivek

unread,
Mar 18, 2019, 8:36:51 AM3/18/19
to Blockly
Hi all
I am implementing scratch junior for horizontal blocks programming. Below is the block ui definition and after that I have provided the toolbox code for block. I have defined a outer block as container and and container block have two blocks as shadow blocks named as control_touch. But it is working fine if I add one shadow block but not working if add two shadow blocks. Please look over it suggest me the changes.:-


ui block.png

Blockly.Blocks['control_sensor_container'] = {
  /**
   * Block for repeat n times (external number).
   * @this Blockly.Block
   */
  init: function() {
    this.jsonInit({
      "id": "control_forever",
      "message0": "%1 %2",
      "args0": [
        {
          "type": "input_statement",
          "name": "SUBSTACK"
        },
        {
          "type": "field_image",
          "src": Blockly.mainWorkspace.options.pathToMedia + "icons/control_forever.svg",
          "width": 40,
          "height": 40,
          "alt": "*",
          "flip_rtl": true
        }
        
      ],
      "inputsInline": true,
      "previousStatement": null,
      "category": Blockly.Categories.control,
      "colour": Blockly.Colours.control.primary,
      "colourSecondary": Blockly.Colours.control.secondary,
      "colourTertiary": Blockly.Colours.control.tertiary
    });
  }
};


Blockly.Blocks['control_touch'] = {
  /**
   * Block for repeat n times (external number).
   * @this Blockly.Block
   */
  init: function() {
    this.jsonInit({
      "id": "control_touch",
      "message0": "%1 %2 %3",
      //"message1": "%1 %2 %3",
      "args0": [
        {
          "type": "input_value",
          "name": "CHOICE"
        },
        {
          "type": "field_image",
          "src": Blockly.mainWorkspace.options.pathToMedia + "icons/control_repeat.svg",
          "width": 40,
          "height": 40,
          "alt": "*",
          "flip_rtl": true
        },
        {
          "type": "input_statement",
          "name": "SUBSTACK"
        }           
      ],
      "inputsInline": true,
      "previousStatement": null,
      "nextStatement": null,
      "category": Blockly.Categories.control,
      "colour": Blockly.Colours.control.primary,
      "colourSecondary": Blockly.Colours.control.secondary,
      "colourTertiary": Blockly.Colours.control.tertiary
    });
  }
};

Toolbox is defined as following:-
'<block type="control_sensor_container">'+
        '<value name="SUBSTACK">' +
        '<block type="control_touch">' +
        '<value name="CHOICE">' +
        '<shadow type="control_sensor_values_dropdown">' +
        '<field name="CHOICE">Pressed</field>' +
        '</shadow>' +
        '</value>' +
        '</block>' +
        /*'</value>' +
        '<value name="SUBSTACK1">' +*/
        '<block type="control_touch">' +
        '<value name="CHOICE">' +
        '<shadow type="control_sensor_values_dropdown">' +
        '<field name="CHOICE">Pressed</field>' +
        '</shadow>' +
        '</value>' +
        '</block>' +
        '</value>' +
  '</block>' +


Thank You
Vivek

Erik Pasternak

unread,
Mar 18, 2019, 1:16:55 PM3/18/19
to Blockly
Hi Vivek,

I think I'm missing something, the control_sensor_container block you sent doesn't have a SUBSTACK1 as far as I can tell, just a SUBSTACK. I'm not sure how you got two blocks in that screenshot with the code you sent.

If you want to have two shadow blocks inside a single input you'll want to put the second one inside the <next> tag of the first one. Here's an example using the playground:
  <block type="controls_whileUntil">
    <statement name="DO">
      <shadow type="text_print" >
        <next>
          <shadow type="text_print" >
          </shadow>
        </next>
      </shadow>
    </statement>
  </block>

If you're trying to create a block with two statement inputs, though, I don't think the Scratch team has support for that. They've kept the design language for the horizontal blocks pretty limited so adding more complex blocks requires some additional work on the rendering side.

Let me know if I misunderstood something.

Cheers,
Erik

Vivek

unread,
Mar 19, 2019, 3:04:40 AM3/19/19
to Blockly
Hi Erik
Thanks for your support and spending your precious time on this.
Ya you understood right that I want to have a block which have one statement input and this statement input have two blocks in it by default(as shadow block).
I just got two blocks by simply drag drop in the container field but I want that type of block in toolbox so that I do not require to drag 3 blocks for this purpose instead I just drag one block that will contain those blocks as shadow blocks. And SUBSTACK1 was commented code which will not be executed.

I have tried your solution using the next statement in toolbox block code as below and its working but I also want that Dropdown value in second block should be different from the first block so that it works something like if(){}else{}. 

       '<block type="control_sensor_container">' +
      '<statement name="SUBSTACK">' +
         '<block type="control_touch" movable="false">' +
            '<value name="CHOICE">' +
               '<shadow type="control_sensor_values_dropdown">' +
                  '<field name="CHOICE">Pressed</field>' +
               '</shadow>' +
            '</value>' +
            '<next>' +
               '<block type="control_touch" movable="false">' +
                  '<value name="CHOICE">' +
                     '<shadow type="control_sensor_values_dropdown">' +
                        '<field name="CHOICE">Not_Pressed</field>' +
                     '</shadow>' +
                  '</value>' +
               '</block>' +
            '</next>' +
         '</block>' +
      '</statement>' +
   '</block>' +

Now the another issue is:-
1) Dropdown value in second block should be different from the first block so that it works something like if(){}else{}. 


And it is showing the block as I want:-

sensor.png





Now I am facing these two issues.

Erik Pasternak

unread,
Mar 19, 2019, 12:54:53 PM3/19/19
to Blockly
Hi Vivek,

I'm not sure what the issues are. What you wrote seems correct and looks like it's working. What isn't working? Also, you never included the initializer for your control_sensor_values_dropdown, so I have no way to confirm the CHOICE field is correct.
Reply all
Reply to author
Forward
0 new messages