How to create composite blocks in blockly

186 views
Skip to first unread message

Abhigya jain

unread,
Jul 28, 2017, 7:09:42 AM7/28/17
to Blockly
Hi Team,

I want to be able to create a composite block in blockly. What i mean by a 'composite block' is one which i could create just like i create a new variable in blockly by clicking on the 'create variable' button in the flyout and user gives it a custom name + I should be able to drag and drop multiple blocks into this composite block and this one composite block should 'encapsulate' the blocks added onto it.

I had been going over how Variables are coded for in blockly and i observed that the code expanses too many classes and that i might miss out on a few details while trying to replicate the behaviour at my end for composite blocks.
Could someone please help me with what all files i should focus on to implement this.

Or suggest a better way to achieve the above.

Regards
Abhigya Jain

Erik Pasternak

unread,
Jul 28, 2017, 10:02:53 AM7/28/17
to Blockly
Hi Abhigya,

Does adding the functions category to your toolbox do what you want? That's a special category provided by Blockly for users to build their own functions.

<category name="Functions" custom="PROCEDURE"></category>

Abhigya jain

unread,
Jul 28, 2017, 10:34:55 AM7/28/17
to Blockly
Thanks for your reply Erik, but i am not sure if this would help me achieve what i want to.

Just like Blockly variables are saved in the variables flyout when i create them (they persist), similarly i would want a composite block to be a user defined block that gets created on the click of a button and that persists or gets saved in the 'composite blocks' flyout to be used/reused in the workspace.

With functions, though i achieve the objective of clubbing multiple blocks within a single block, but the function block is just like any other loop block(for example) in that it does not get saved in the toolbox flyout. and cannot be created as and when the user wants to.

But i really appreciate you mentioning it. I will look into it more.

Erik Pasternak

unread,
Jul 28, 2017, 12:03:57 PM7/28/17
to Blockly
We don't have direct support for saving functions outside of the current workspace. I'd suggest starting with functions and adding in some code to save those definitions and use them to populate a dynamic flyout similar to the function flyout.

--
You received this message because you are subscribed to a topic in the Google Groups "Blockly" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/blockly/CoFg-D8D-lA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to blockly+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Erik Pasternak | Master of the House | epas...@google.com     
Reply all
Reply to author
Forward
0 new messages