Type checker message

71 views
Skip to first unread message

STeEL

unread,
Jan 27, 2021, 2:08:57 AM1/27/21
to Blockly
Hi,

Does blockly type checker provide message when two blocks connected or disconnected because of type checker?
if it does, could you give me an example how to do it?

~STeEL


Beka Westberg

unread,
Jan 27, 2021, 4:32:22 PM1/27/21
to blo...@googlegroups.com
Hi STeEL,

> Does blockly type checker provide message when two blocks connected or disconnected because of type checker?

Hmm, do you mean like provide a message to the developer? Or provide a message to the user?

If you mean the former, technically the connection checker interface has a canConnectWithReason function that returns information about why an attempted connection failed, but you have to call it explicitly. For example the keyboard navigation code does this.

If you mean the latter, the simple answer is no :/ I think Blockly's philosophy is that if two blocks can't connect, the user should be able to figure out why from other info (eg the color of the block, its fields, connection shapes, etc).

However, if you do want to give some more information to the user you should be able to use the connection checker interface to do that. Eg if your type checks fail in doTypeChecks, you could send a message to a different system (which you build) that could display a message to the user.

I hope that helps! If you have any further questions please reply :D
--Beka

--
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/a1090144-cb79-4677-a589-beff59d77244n%40googlegroups.com.

STeEL

unread,
Feb 3, 2021, 3:16:58 AM2/3/21
to Blockly
Thank you Beka,

I meant, block event like 'onchange' or 'compose' for mutator. Maybe, it is doTypeChecks from connection checker interface. BTW, can you give an example code how to use doTypeChecks or connection checker interface if I have block like:

Blockly.Blocks['var_setter'] = {
init: function() {
this.appendValueInput("input_value")
.setCheck("Number")
.appendField("set x to");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(230);
this.setTooltip("");
this.setHelpUrl("");
}
};

~STeEL

Beka Westberg

unread,
Feb 3, 2021, 6:11:59 PM2/3/21
to blo...@googlegroups.com
> I meant, block event like 'onchange' or 'compose' for mutator. Maybe, it is doTypeChecks from connection checker interface.

Yeah there is not a function on the block (like `onchage` or `compose`) that gets called for this situation :/

After thinking about it for a while, I think doTypeChecks might not be right for your situation either. Your best bet is probably to create an event listener that watches for move events. Someone actually had a similar question to this yesterday which I answered here. I think it should work pretty well for your situation =)

Best,
Beka

Reply all
Reply to author
Forward
0 new messages