How to do recursion

I have a set of objects arranged in a hierarchy via “Attachment.” I’d use grouping but groups can’t be edited without first deleting the group, making the group construct unwieldy for rapid iteration.
I’d like to be able to change the visibility of all the objects that are attached, recursively but various strategies aren’t reliably working. If someone could take a look at my Space and help me understand the “correct” way to do recursion, I’d be very helpful.


  • Dan

Hi @Daniel_Robbins!

Your code was getting close to the solution. Below you can find an adjusted version of your space with working recursion. Please have a look at how it’s achieved.

It’s important to point out that CoSpaces allows parenting of items to create a hierarchy (see Cuboid-parent item), as well as grouping of items (see Group01 item). There are two functions in the example space that cover both item-types.

To copy the space and read the CoBlocks code used, press the ‘remix button’.

Hope the example makes iterating through child items clear!


Hello Daniel,

we discussed recently similar problem in parallel thread (Is it possible to code a grouped panel and text?). As an author of this thread you also use opacity to hide or show multiple objects. I decided to quote part of my answer and to edit it for your case.

You are dealing with hierarchies of objects: nested figures and grouped figures. Generally some objects properties are inherited from it’s parent: if you change position or orientation of parent object, child objects also change thier positions.

However in general opacity property is not inherited from parent object, because otherwise it would be hard to make parent object more transparent than child. Opacity is inherited only from groups, because group doesn’t have it’s own body and it’s opacity can be used to simultaneous control of children opacities.

So, the simplest way to apply some opacity value to multiple objects is to group them and apply this value to group’s opacity (either from editor or from blockly).

If you want control opacity of hierarchy of nested figures you should create a single group above top figure: here is described how to do this for text panel which is also hierarchy of two elements.

Unfortunately this approach (!!!) doesn’t work in current version (!!!) of our application because of some wrong coding. These bugs are already fixed and update will come in next release. Sorry for inconvenience!

1 Like