Mutator with shadow input

77 views
Skip to first unread message

1234567890

unread,
May 29, 2024, 6:33:40 AMMay 29
to Blockly
Hello,

I'm trying to modify the "text_join" block so that all of the inputs have the "text" block as a shadow.


input.connection.setShadowState({'type': 'text'});

And this work (kind of), but whenever I remove inputs from the text_join block, they don't just disappear, they get dropped as regular 'text' blocks into the world, which trigger an exception when trying to touch them (unless you save and load).

How would I go about making the text_join block have shadow inputs of text?

Christopher Allen

unread,
May 29, 2024, 8:27:23 PMMay 29
to blo...@googlegroups.com
Hello,

I'm trying to modify the "text_join" block so that all of the inputs have the "text" block as a shadow.

So, normally shadow blocks are provided by the toolbox definition rather than by the block definition—but as you have discovered, it is quite possible for a block definition to provide its own shadow blocks.


input.connection.setShadowState({'type': 'text'});

And this work (kind of), but whenever I remove inputs from the text_join block, they don't just disappear, they get dropped as regular 'text' blocks into the world, which trigger an exception when trying to touch them (unless you save and load).

It seems like the issue is that JOIN_MUTATOR_MIXIN.compose is calling connection.disconnect() on the connection of each deleted input, and this function obediently disconnects the shadow block, dropping it on to the workspace.  I see that this is a known bug.
 
How would I go about making the text_join block have shadow inputs of text?

The most straightforward workaround is to modify compose to call connection.setShadowState(null) before calling connection.disconnect().


Best wishes,

Christopher


1234567890

unread,
Jun 4, 2024, 6:34:12 PMJun 4
to Blockly
Hey!

This works- thanks. Now they're being removed. But I have a new problem now. The shadow blocks are only being added properly when I put "item" as the last block in the mutator-- the shadow block appearing in the rightmost position. When I put it in any other position, it breaks.

Here is my sample code : https://pastebin.com/4DRTnrqt - am I doing something wrong? I don't see why it wouldn't work in any position-- the for loop clearly goes through every block, not just the newest one, right?

Beka Westberg

unread,
Jun 6, 2024, 12:49:20 PMJun 6
to Blockly
Hello,

It looks like you have an early return on line 127 that means that a shadow won't get added if an input already exists. You probably want to make sure the shadow gets added regardless of whether the input exists. But I didn't actually pull down your code to test it, so I'm not 100% sure. Let me know if that fixes it or if there are still issues!

Best wishes,
--Beka

1234567890

unread,
Jun 13, 2024, 11:26:28 AMJun 13
to Blockly
Hi, sorry for the late reply. I don't think this helps because it's not just not creating the shadow block, it's creating it but not attaching it. It just hangs out stray.

Also, line 127 is not a return, it's an if, however, I confirmed that that part inside the if *does* run when the block comes back.

If you could take the time to run the example I'd greatly appreciate it, thanks for any help you can provide (note that the "blocks.js" in the HTML is actually "blockly.min.js", I renamed it)
Reply all
Reply to author
Forward
0 new messages