scratchfoundation / scratch-gui

Graphical User Interface for creating and running Scratch 3.0 projects.
https://scratchfoundation.github.io/scratch-gui/develop/
BSD 3-Clause "New" or "Revised" License
4.41k stars 3.5k forks source link

Default values for dropdown menus lost upon instantiation in the work space #971

Closed WilliamHarmonMS closed 6 years ago

WilliamHarmonMS commented 6 years ago

Expected Behavior

When creating new custom blocks, drop down menus should have default arguments

Actual Behavior

Upon instantiation, the default arguments for drop down menus revert to 'undefined'

Steps to Reproduce

Here are some images to show what I mean: We see that in the toolbox, there are default arguments for both fields in the block: image

However, upon instantiation, the default value for the dropdown menu is lost (UNLIKE the motion block which is shown for comparison). image

To compare those two blocks right there, as they’re defined in make-toolbox-xml.js within the scratch-gui repo, we see: value name="INDEX" shadow type="minecraft_agentindex_menu" /shadow /value Vs value name="TO" shadow type="motion_glideto_menu" /shadow /value

Likewise their definitions in \scratch-blocks\blocks_vertical\file_name.js and \scratch-vm\src\blocks\scratch3_file_name.js are identically formatted.

Does anyone have any idea why default arguments, when instantiated are lost in new blocks?

Operating System and Browser

Win10 | version 1709 | OS Build 16299.19

Browser: N/A, I am hosting the environment within the webview of an Electron application.

thisandagain commented 6 years ago

Hmm. Any thoughts on this one @paulkaplan?

paulkaplan commented 6 years ago

Could you provide steps that I could use to reproduce something like this locally? Here is what I tried:

  1. Created a new block based on the glide to and the glide to menu
    
    Blockly.Blocks['motion_dummy'] = {
    init: function() {
    this.jsonInit({
      "message0": "glide %1 secs to %2",
      "args0": [
        {
          "type": "input_value",
          "name": "SECS"
        },
        {
          "type": "input_value",
          "name": "TO"
        }
      ],
      "category": Blockly.Categories.motion,
      "extensions": ["colours_motion", "shape_statement"]
    });
    }
    };

Blockly.Blocks['motion_menu'] = { init: function() { this.jsonInit({ "message0": "%1", "args0": [ { "type": "field_dropdown", "name": "TO", "options": [ ['1', '1'], ['2', '2'] ] } ], "colour": Blockly.Colours.motion.secondary, "colourSecondary": Blockly.Colours.motion.secondary, "colourTertiary": Blockly.Colours.motion.tertiary, "extensions": ["output_string"] }); } };


2. Added the blocks to the default toolbox
'<block type="motion_dummy">'+
  '<value name="SECS">'+
    '<shadow type="math_number">'+
      '<field name="NUM">1</field>'+
    '</shadow>'+
  '</value>'+
  '<value name="TO">'+
    '<shadow type="motion_menu">'+
    '</shadow>'+
  '</value>'+
'</block>'+


3. Menu works correctly in the toolbox like you said

4. I'm not exactly sure what you mean by "instantiate". I tried dragging the block out of the toolbox, saving the XML and opening reloading it (using the "vertical playground" in scratch-blocks). Seemed to work correctly. How can I reproduce what you were seeing?
paulkaplan commented 6 years ago

Closing due to lack of activity