Thanks, that works great. I have an issue though where it runs through once perfectly, but then on any time after that, more than one object moves. I'll post the code, and would you be able to see where the issue lies? I added in a function ('prep') that keeps the screen blank and waits for a space press before going to 'sceneOn', and a mouseclick goes to 'prep'. Thanks
Code:
import random
objects = [bottle, candle, clamp, lock, wood]
def prep():
viz.MainScene.visible(viz.OFF)
vizact.onkeydown(' ', sceneOn,1)
rand_positions = []
def sceneOn(num):
global rand_positions
positions = [0,1,2,3,4,5,6,7,8]
if num == 1:
#set objects to 5 different random positions
rand_positions = random.sample(positions,5)
objects[0].setPosition(pos[rand_positions[0]])
objects[1].setPosition(pos[rand_positions[1]])
objects[2].setPosition(pos[rand_positions[2]])
objects[3].setPosition(pos[rand_positions[3]])
objects[4].setPosition(pos[rand_positions[4]])
vizact.ontimer2(3,0,sceneOff)
elif num == 2:
#choose one object to move randomly and leave others in their places
#first get available positions
diff_list = [item for item in positions if not item in rand_positions]
rand_position = random.sample(diff_list,1)[0]
#choose one of the objects
rand_obj = random.randint(0,4)
#set the randomly chosen object to the new random position
objects[rand_obj].setPosition(pos[rand_position])
print 'object ' + str(rand_obj) + ' moved to position ' + str(rand_position)
viz.MainScene.visible(viz.ON)
def sceneOff():
viz.MainScene.visible(viz.OFF)
vizact.ontimer2(10,0,sceneOn,2)
prep()
Again, this isn't the complete code, but where I would think the issue lies.