list of objects in a compound object

19 views
Skip to first unread message

Jamie Kellogg

unread,
Nov 6, 2017, 6:02:24 PM11/6/17
to Glowscript Users
Howdy.  I have some students building Tetris and some other games for which moving objects in and out of compounds seems desirable.  Is there a way to get a list of the objects in a compound object?  Also, is there a way to add and remove objects from a compound once it has been made?  
Thanks in advance,
Jamie

Bruce Sherwood

unread,
Nov 6, 2017, 10:25:14 PM11/6/17
to Glowscript Users
The following program demonstrates that when a compound is created the objects making up the compound have visible set to False, but they still exist, so you can have a list of the objects, the list used to make the compound:

b = box(pos=vec(-1,0,0), color=color.red)
s = sphere(pos=vec(1,0,0), color=color.green)
o = [b,s]
c = compound(o)
c.pos.y = 2
print(o[0].pos, o[1].pos) # <-1,0,0> <1,0,0>

There is no way to remove an object from a compound, but you can add to it. Here is additional code to add a pyramid to the existing compound:

p = pyramid()
c2 = compound([c,p])
c2.axis = vec(2,2,0)

The key point here is that among the kinds of objects that can make up a compound is an existing compound.

Bruce

Jamie Kellogg

unread,
Nov 7, 2017, 12:35:07 AM11/7/17
to Glowscript Users
Got it.  Thanks!

Bruce Sherwood

unread,
Nov 7, 2017, 9:02:10 AM11/7/17
to glowscri...@googlegroups.com
Also, note that you can make additional copies of an object, including a compound object, by using the "clone" function:

Reply all
Reply to author
Forward
0 new messages