Error message on invalid block connection

54 views
Skip to first unread message

lingareddy kotanka

unread,
Apr 19, 2023, 2:53:49 AM4/19/23
to Blockly
Hello Team,

Greetings!
I have created some custom blocks which can be vertically stacked. and i have added types on which block can be connected next/prev.
if a user tries to connect two blocks with invalid type the block moves away. so is there any way we can show message to the user that why it cannot be connected?

Thanks in advance,
Best regards

Neil Fraser

unread,
Apr 19, 2023, 5:54:10 AM4/19/23
to blo...@googlegroups.com
That's a really good question.  I can't think of a good way using the current API.

Proposal: the move event should have a 'reason' field that records what caused the move.
* 'drag' -- User action.
* 'snap' -- Alignment to grid.
* 'bump' -- Incompatible connection type.
* undefined -- Some other move, perhaps programmatically generated.

How does that sound?  If nothing else, this would certainly make reading the log easier, since there are often a stack of up to three move events that appear all at once.  Under this proposal, you'd be able to identify the block that was bumped, but not which connection triggered the bump, nor what the other block was.

--
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/543aea1d-c36e-4fc3-9278-b65d4dcf8d83n%40googlegroups.com.


--
Neil Fraser, Switzerland
https://neil.fraser.name

lingareddy kotanka

unread,
Apr 19, 2023, 8:33:00 AM4/19/23
to Blockly

Hello Neil Fraser,

Thanks you,
I just checked the event by logging and I do not see 'reason' field for 'move' event
I am currently using Blockly - 9.2.1
this.workspace.addChangeListener((event)=>{ console.log(event) }

Neil Fraser

unread,
Apr 19, 2023, 10:17:38 AM4/19/23
to blo...@googlegroups.com
The 'reason' property doesn't exist.  It's just a proposal.  Would it be helpful for your use case?

Sent (awkwardly) from an Android device.

lingareddy kotanka

unread,
Apr 19, 2023, 10:27:47 AM4/19/23
to Blockly
Hello Neil Fraser,

Yes, having 'reason' field would help in my case

Beka Westberg

unread,
Apr 19, 2023, 1:59:28 PM4/19/23
to Blockly
Hello!

Alternatively, you could probably also detect this using a custom conection checker. The `canConnection` method calls `canConnectWithReason` which returns a number which specifies whether the connections can connect, and if not why not. So you should be able to create a custom connection checker, and then add code that informs the user of the failure to the `canConnect` method.

E.g.:

```
class MyConnectionChecker extends Blockly.ConnectionChecker {
  canConnect(a, b, isDragging, distance) {
    const reason = this.canConnectWithReason(a, b, isDragging, distance);
    switch (reason) {
      // Add surfacing information about the failure here.
    }
   return reason === Connection.CAN_CONNECT;
  }
}
```

Here's an example of creating a simple custom connection checker.

I hope that helps! If you have any further questions please reply =)
--Beka
Reply all
Reply to author
Forward
0 new messages