Type variables with blockly developper tools

851 views
Skip to first unread message

Francois Thibault

unread,
Mar 2, 2018, 12:50:56 PM3/2/18
to Blockly
Hi,

Based on information I got at https://developers.google.com/blockly/guides/create-custom-blocks/variables#typed_variable_blocks I was expecting to be able to create my own variable blocks with custom defined types. So using manual JSON on new object, I tried using the following manual JSON definitions. I cannot save the block unless I switch out of the manual mode, and when I do, my object definition gets replaced by the default template. What am I missing? Is is still supported to provide custom typed variable blocks?

Thanks,
Francois

{
  "type": "variables_get_panda",
  "message0": "%1",
  "args0": [
    {
      "type": "field_variable",
      "name": "VAR",
      "variable": "%{BKY_VARIABLES_DEFAULT_NAME}",
      "variableTypes": ["Panda"]
    }
  ],
  "output": "Panda", 
  "colour": 230,
  "tooltip": "",
  "helpUrl": ""
}

{
  "type": "variables_set_panda",
  "message0": "%{BKY_VARIABLES_SET}",
  "args0": [
    {
      "type": "field_variable",
      "name": "VAR",
      "variable": "%{BKY_VARIABLES_DEFAULT_NAME}",
      "variableTypes": ["Panda"]
    },
    {
      "type": "input_value",
      "name": "VALUE",
      "check": "Panda"
    }
  ],
  "previousStatement": null,
  "nextStatement": null,
  "colour": 230,
  "tooltip": "",
  "helpUrl": ""
}

Rachel Fenichel

unread,
Mar 2, 2018, 8:53:03 PM3/2/18
to Blockly
Hi Francois,

The developer tools don't yet handle typed variables.  I suggest adding that block to your local copy of playground.html instead.

Best,
Rachel

Andrew n marshall

unread,
Mar 6, 2018, 11:48:32 AM3/6/18
to blo...@googlegroups.com
I'm working on updating the developer tools now, and I'll add this to the wish list.  Thanks for bringing this up.

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vivek

unread,
Mar 13, 2018, 2:30:25 AM3/13/18
to Blockly
Hello all 
I have to change the the colors of the block in blockly
Please tell how can I achieve this.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.

Francois Thibault

unread,
Mar 21, 2018, 12:13:23 PM3/21/18
to Blockly
Working the examples out of the playground got me much further thanks! There is only one gotcha remaining...

So I using the panda examples, I have created custom blocks to set/get the panda type blocks which I have exposed to the toolbox in their own panda category. I have also added a create variable button hooked to BlocklyVariable.createVariable call that can create a panda typed variable. So far so good. When I try to use my panda getter/setter however, a new untype variable automatically gets created in the workspace. How do I avoid that? I want my getter/setter to be specific to the panda type and only list variables of that type as a possibility.

// Block for Panda variable getter.
 {
  "type": "variables_get_panda",
  "message0": "%1",
  "args0": [
    {
      "type": "field_variable",
      "name": "VAR",
      "variable": "",
      "variableTypes": ["panda"]    // Specifies what types to put in the dropdown
    }
  ],
  "output": "panda",    // Returns a value of "Panda"
  "colour": "%{BKY_VARIABLES_HUE}",
  "helpUrl": "%{BKY_VARIABLES_GET_HELPURL}",
  "tooltip": "%{BKY_VARIABLES_GET_TOOLTIP}",
  "extensions": ["contextMenu_variableSetterGetter"]
},
 // Block for Panda variable setter.
{
  "type": "variables_set_panda",
  "message0": "%{BKY_VARIABLES_SET}",
  "args0": [
    {
      "type": "field_variable",
      "name": "VAR",
      "variable": "",
      "variableTypes": ["panda"]
    },
    {
      "type": "input_value",
      "name": "VALUE",
      "check": "Panda"    // Checks that the input value is of type "Panda"
    }
  ],
  "previousStatement": null,
  "nextStatement": null,
  "colour": "%{BKY_VARIABLES_HUE}",
  "tooltip": "%{BKY_VARIABLES_SET_TOOLTIP}",
  "helpUrl": "%{BKY_VARIABLES_SET_HELPURL}",
  "extensions": ["contextMenu_variableSetterGetter"]
}

// create panda variable button callback
function createPanda(button) {
  Blockly.Variables.createVariable(workspace, null, 'panda');
}

// panda create variable button callback registration
workspace.registerButtonCallback("createPanda", createPanda);

Any cues here?

Thanks,
Francois

Vivek

unread,
Mar 22, 2018, 5:46:42 AM3/22/18
to Blockly
I want to know the file where this code needs to be saved.
in index.html or custom_blocks.js ,etc.
Its a json code and we have written javascript code in custom_blocks.js file.
Please tell how to write this code in java script.

Francois Thibault

unread,
Mar 22, 2018, 5:51:45 AM3/22/18
to blo...@googlegroups.com

On my side, the new blocks were simply added to the list of things already defined in the variables.js in the blocks folder which the playground uses (uncompressed). I will let more qualified people answer you on how to translate this into JS representation.

 

Francois

--
You received this message because you are subscribed to a topic in the Google Groups "Blockly" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/blockly/f93b9FuuJAU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to blockly+u...@googlegroups.com.

Rachel Fenichel

unread,
Mar 22, 2018, 2:12:50 PM3/22/18
to Blockly
Hi Francois,

When was the last time you pulled from master?  The February release had a lot of fixes for typed variables.  If you're on an earlier version you may be running into a problem that we have sicne solved.

Rachel

Francois Thibault

unread,
Mar 22, 2018, 3:53:29 PM3/22/18
to Blockly
Just before the February release. I have since updated and no longer have the problem. 

Thanks!
Francois
Reply all
Reply to author
Forward
0 new messages