Get type of connected output port

96 views
Skip to first unread message

Bart Butenaers

unread,
Sep 12, 2018, 2:56:39 PM9/12/18
to Blockly
Hi folks,

I have a block that can accept on its input both Dates or Strings:

Blockly.Blocks['myBlock'] = {
    init
: function () {
       
this.jsonInit({
           
...
           
"args0": [
               
{
                   
"type": "input_value",
                   
"name": "someDate",
                   
"check": ["String", "Date"]
               
},
           
],
           
...
       
});
   
}
};

This means that I could connect this input to the output of another block that generates e.g. a Date:

Blockly.Blocks['myOtherBlock'] = {
    init
: function () {
       
this.jsonInit({
           
...
            "output": "Date",
            ...
       
});
   
}
};

In my code generator I would like to do some extra stuff when the input is connected to a "Date" output port:

Blockly.JavaScript['myBlock'] = function (block) {
   
var code;
   
if (output connected to "someDate" input is "Date" ?????????????????? ) ....
   
   
return [code, Blockly.JavaScript.ORDER_ATOMIC];
};

Does anybody know how I write this test ???
Could I someway use e.g. getInput("someDate").connection ....

Thanks !!!!
Bart

Rachel Fenichel

unread,
Sep 12, 2018, 5:55:15 PM9/12/18
to Blockly
You're on the right track: get your input by name, then get its connection.  


var myConnection;
var targetConn = myConnection.targetConnection;


Then you can inspect the checks on the target:
var targetTypes = targetConn.checks_;



It's an array, so you will need to check length and/or just grab the first one.

It looks like we don't have a way to expose the checks_ array without just inspecting it directly.  I'll file a bug for that.

Rachel

Bart Butenaers

unread,
Sep 13, 2018, 2:35:16 PM9/13/18
to Blockly
Hi Rachel,

Thanks !!
PS. Once you have created an issue, could you please share the link to it here?

Kind regards,
Bart

Rachel Fenichel

unread,
Sep 13, 2018, 3:02:34 PM9/13/18
to Blockly
Here's the bug, but it's already been fixed on develop thanks to @duzc2.

Cheers,
Rachel
Reply all
Reply to author
Forward
0 new messages