![]() |
|
#1
|
|||
|
|||
Ok, everything works great so far. The only problem is that I am getting some kind of traceback error.
Code:
Traceback (most recent call last): File "Test2WithEyeAdjustment.py", line 185, in mytimer avatar = avatars[nextAvatar] IndexError: list index out of range Code:
def mytimer(num): global avatars if num == ANIMATION: #Calculate elapsed time since last update elapsed = viz.elapsed() #Update each active ball for bullet in bullets: if bullet.active: #Move the ball and check if it has collided with any objects MoveBullet(bullet,elapsed) elif num == START_AVATAR: global nextAvatar #Get the next available avatar and start it avatar = avatars[nextAvatar] #favatar = favatars[nextAvatar] walkAvatar(avatar) #walkAvatar(favatar) nextAvatar = (nextAvatar + 1) % NUM_AVATARS viz.starttimer(START_AVATAR,TIME_BETWEEN_AVATARS) #Create callbacks for timer events viz.callback(viz.TIMER_EVENT,mytimer) Code:
def shootBullet(): global nextBullet #find the next available ball to shoot bullet = bullets[nextBullet] nextBullet = (nextBullet + 1) % NUM_BULLETS #Calculate the vector of the ball based on the mouse position pos = viz.mousepos() bulletvector = viz.screentoworld(pos[0]+0.25,pos[1]) #Need to account for stereo bullet.vector = viz.Vector(bulletvector[3]-bulletvector[0],bulletvector[4]-bulletvector[1],bulletvector[5]-bulletvector[2]) bullet.vector.normalize() bullet.vector *= BULLET_SPEED #translate the bullet to the head position bullet.translate(viz.get(viz.HEAD_POS)) #make the bullet visible bullet.visible(viz.ON) #mark the bullet as active bullet.active = 1 def MoveBullet(bullet,elapsed): #get the bullet's current position pos = bullet.get(viz.POSITION) #calculate the balls future position based on it's velocity futurePos = pos + (bullet.vector * elapsed) #Check if bullet intersected with anything info = viz.intersect(pos,futurePos) if info.intersected: if info.object in avatars: #viz.starttimer(FREEZE_AVATAR,info.object.getduration(7)-0.1) WaitThenFreeze = vizact.sequence( vizact.waittime(info.object.getduration(7)-0.05), vizact.speed_node(0) ) info.object.execute(7) info.object.clear(viz.ALL) info.object.clear(viz.CURRENT_ACTION) info.object.add(WaitThenFreeze) #Add the action to the avatar RemoveAvatarAction = vizact.call(RemoveAvatar,info.object) info.object.add(RemoveAvatarAction) #Add action to remove avatar bullet.visible(0) bullet.active = 0 #Update balls positions bullet.translate(futurePos.get()) #Shoot a ball whenever left mousebutton is clicked vizact.onmousedown(viz.MOUSEBUTTON_LEFT,shootBullet) |
#2
|
|||
|
|||
Hi,
That means you are trying to index into the avatar list with a value greater than the size of the list. Are you deleting items from the avatar list after you create it? If so then you need to change the way you increment to the next avatar: Code:
nextAvatar = (nextAvatar + 1) % len(avatars) |
#3
|
|||
|
|||
I'm still getting the same error. I'm not sure what is causing it. When a bullet "hits" or intersects an avatar, the following code is called:
Code:
if info.intersected: if info.object in avatars: WaitThenFreeze = vizact.sequence( vizact.waittime(info.object.getduration(7)-0.005), vizact.speed_node(0) ) info.object.execute(7) info.object.clear(viz.ALL) info.object.clear(viz.CURRENT_ACTION) info.object.add(WaitThenFreeze) #Add the action to the avatar RemoveAvatarAction = vizact.call(RemoveAvatar,info.object) info.object.add(RemoveAvatarAction) #Add action to remove avatar Code:
def RemoveAvatar(avatar): avatar.visible(0) #Hide avatar avatar.speed(1) #Restore speed avatars.remove(avatar) #Remove from list dead_list.append(avatar) #Add to dead list I also tried: Code:
if len(avatars) != NUM_AVATARS: avatar = dead_list[nextAvatar] nextAvatar = nextAvatar + 1 % len(dead_list) else: avatar = avatars[nextAvatar] nextAvatar = (nextAvatar + 1) % len(avatars) walkAvatar(avatar) Last edited by betancourtb82; 03-21-2006 at 09:35 AM. |
![]() |
Thread Tools | |
Display Modes | Rate This Thread |
|
|