I'm having big troubles with a program that I need to release to students tomorrow. I've cut it down to a small sample. There's a simple function that creates a compound and returns it. Printing in the function demonstrates that the compound is what I want. But after I call it, it turns into a Promise, which is undocumented.
Here's a minimal example:
GlowScript 3.1 VPython
scene.width = 640
scene.height = 480
def make_alien(starting_position, starting_vel = vec(0, 0, 0)):
print("in make_alien")
alien_body = sphere(size = 1.0*vec(1, 1, 1), pos = vec(0, 0, 0), color = color.green)
alien_eye1 = sphere(size = 0.3*vec(1, 1, 1), pos = .42*vec(.7, .5, .2), color = color.white)
alien_objects = [alien_body, alien_eye1]
print("making compound, pos =", starting_position)
print("alien objects are", alien_objects)
com_alien = compound(alien_objects)
print("setting position")
com_alien.pos = starting_position
print("setting velocity")
com_alien.vel = starting_vel
print("compound type is", type(com_alien))
print("compound contents are", com_alien)
print("returning com_alien")
return com_alien
print("making alien1")
alien1 = make_alien(starting_position = vec(6, 0, -6), starting_vel = vec(0, 0, -1))
print("alien1 is a", type(alien1))
print("alien1 is", alien1)
print("made alien1", dir(alien1))
print("pos is", alien1.pos)
print("promise offers", dir(Promise))
RATE = 30
scene.autoscale = False
scene.forward = vec(0, -3, -2)
while True:
rate(RATE)
And here's some sample output:
making alien1
in make_alien
making compound, pos = < 6, 0, -6 >
alien objects are [[object Object], [object Object]]
setting position
setting velocity
compound type is <class 'dict'>
alien1 is a <class 'promise'>
alien1 is [object Promise]
made alien1 []
pos is undefined
promise offers []
Note that "returning com_alien" doesn't appear! If I comment out the "compound contents are" line, then "returning com_alien" appears but nothing else changes.