Generate a custom block with non-visible blocks inside

50 views
Skip to first unread message

Jana

unread,
Sep 3, 2021, 2:59:05 AM9/3/21
to Blockly
Hi,
I want to create a custom block in Blockly where other custom blocks are nested. The special thing about this is that the blocks in my other block are already filled with information and should not be able to be edited. The final block should look like the one on the right but still have all the information (in code) that is shown on the left.
Is there a way to implement this in Blockly?
Thanks a lot!
example.PNG

Jason Schanker

unread,
Sep 4, 2021, 9:22:23 PM9/4/21
to Blockly
Hi,

Yes, you can call setVisible on the statement input like this:

block.getInput('INPUTNAME').setVisible(false);

However, this is a package method so it's not intended for you to call it directly.  If you do call it, you may want to also call Blockly.getMainWorkspace().render() afterward so you don't see empty space where the blocks would reside.  Note that a user could get these blocks in the statement input back by collapsing and expanding the block so you may want to remove this option from the context menu, or alternatively use a combination of setMovable and setEditable to make it so that these blocks can't be moved or changed if the user decides to show them.

Best,
Jason
Reply all
Reply to author
Forward
0 new messages