I am also trying to remove items using object.remove. First, I add 4 avatars (NUM_AVATARS) to an array. They will be removed as they are shot by the user. The problem I'm having is how to add them again if one of them is taken off. I have the 4 avatars, but I would like for them to be added to the array once they have been shot (causing a remove). I was thinking of saying something like "if the number of array elements is not 4, add another avatar". Can I do this and if so, how. Also, would this be the best way to go about doing this. Here is what I have so far.
Code:
Create avatars coming from the front
for i in range(NUM_AVATARS):
newX = -math.cos(-2*i+15) * 2
newZ = math.sin(i^2+1) * 2
male = viz.add('male.cfg')
#male.face(facepic)
male.translate(newX,-10,newZ)
male.rotate(90,-10,0)
#we might be able to use this type of declaration when we need to decide who is safe to shoot and who isn't
male.SafeIndicator = 1
avatars.append(male) #Save avatar in list
print "avatar indicator is", male.SafeIndicator
#Two differnt options for moving avatars
#Create a walk action that will randomly select a location between (-5,-5) and (5,5)
RandomWalkAction = vizact.walkto(vizact.randfloat(-5,5),court,vizact.randfloat(-10,5))
#Create a walk action that will randomly select a location between (-5,-5) and (5,5)
WalkForever = vizact.sequence(vizact.walkto(vizact.randfloat(-2,5),0,vizact.randfloat(-10,5)),viz.FOREVER)
def walkAvatar(starter):
global court
walk = starter.walkto(0,court,-10.5,1,0,2)
#Clear all the avatar's actions, reposition it, and start the walk action
starter.clear(viz.ALL)
# starter.translate(duckBeginPos)
# starter.rotate(duckBeginOri)
starter.act(walk)
#Add walk action to avatar
#starter.add(WalkForever)
#Add walk action to avatar when spacebar is pressed
#vizact.onkeydown(' ',starter.add,RandomWalkAction)
if avatars[0] or avatars[1] or avatars[2] or avatars[3] == 0:
print 'empty avatar at avatar'
avatars.append(male)
walkAvatar(male)
print 'avatar added'