# array list problems

hi all, hopefully i get help here for my noob question!

im doing two array lists, one for the enemys and one for my weapon (bullets). but, why just my last bullets are reacting on my enemy if im doing endless firing?

ā¦
self.enemys = [None for i in range(count)]

``````    for i in range(count):

self.enemys[i].reparentTo(render)
self.enemys[i].setScale(.2,.2,.2)
self.enemys[i].setPos(enemyPOS(i))
``````

ā¦

``````        if (self.keyMap["d"]!=0):

self.proj = [None for ii in range(countX)]
self.proj1 = [None for ii in range(countX)]

for ii in range(countX):

self.proj[ii].reparentTo(render)
self.proj[ii].setScale(.2,.2,.2)

self.proj1[ii].reparentTo(render)
self.proj1[ii].setScale(.2,.2,.2)

self.proj[ii].setPos(X,Y,Z)
self.proj[ii].setHpr(self.direction1)

self.proj1[ii].setPos(X1,Y1,Z1)
self.proj1[ii].setHpr(self.direction1)

fire = LerpPosInterval(self.proj[ii], 500,Point3(0,-100,0), other = self.proj[ii])
fire.start()
fire2 = LerpPosInterval(self.proj1[ii], 500,Point3(0,-100,0), other = self.proj1[ii])
fire2.start()
fire1 = LerpColorInterval(self.proj[ii], 30, Vec4(0,0,1,1), Vec4(1,.5,0,1))
fire1.start()
fire3 = LerpColorInterval(self.proj1[ii], 30, Vec4(0,0,1,1), Vec4(1,.5,0,1))
fire3.start()

``````
``````                for i in range(count):

disPROJ = self.proj[ii].getPos() - self.enemys[i].getPos()
disPROJlength1 = disPROJ.length()
disPROJ.normalize()
``````
``````                    if (disPROJlength1 < 1):
print "HIT"
self.enemys[i].hide()
``````
``````                return Task.cont

``````

ā¦

thx for helpā¦

you know there is [ code ] [ / code ] tags?

I think your problem is some place with naming the task the same or naming your intervals the same (or not naming them at all in this case)
i cant test your code because its incomplete.

``````self.enemys = [None for i in range(count)]
for i in range(count):
self.enemys[i].reparentTo(render)
self.enemys[i].setScale(.2,.2,.2)
self.enemys[i].setPos(enemyPOS(i))

if (self.keyMap["d"]!=0):     # we say if self.keyMap["d"]:

self.proj = [None for ii in range(countX)]   #why 2 arrays?
self.proj1 = [None for ii in range(countX)]
for ii in range(countX):
self.proj[ii].reparentTo(render)
self.proj[ii].setScale(.2,.2,.2)
self.proj1[ii].reparentTo(render)
self.proj1[ii].setScale(.2,.2,.2)

self.proj[ii].setPos(X,Y,Z)
self.proj[ii].setHpr(self.direction1)

self.proj1[ii].setPos(X1,Y1,Z1)
self.proj1[ii].setHpr(self.direction1)

fire = LerpPosInterval(self.proj[ii], 500,Point3(0,-100,0), other = self.proj[ii])
fire.start()
fire2 = LerpPosInterval(self.proj1[ii], 500,Point3(0,-100,0), other = self.proj1[ii])
fire2.start()

fire1 = LerpColorInterval(self.proj[ii], 30, Vec4(0,0,1,1), Vec4(1,.5,0,1))
fire1.start()
fire3 = LerpColorInterval(self.proj1[ii], 30, Vec4(0,0,1,1), Vec4(1,.5,0,1))
fire3.start()

for i in range(count):

disPROJ = self.proj[ii].getPos() - self.enemys[i].getPos()
disPROJlength1 = disPROJ.length()

# disPROJ.normalize() this statement does not make sence

if (disPROJlength1 > 1):
print "HIT"
self.enemys[i].hide()

wow, thx for the quick reply but its still not workingā¦
so here a quick demo which should shows you the array bug ā¦

``````#test array list bug
#drh 2008

import direct.directbase.DirectStart
from direct.showbase import DirectObject
from direct.actor.Actor import Actor
from direct.interval.IntervalGlobal import *
from pandac.PandaModules import Point3
import math

count = 100
raw = 10

class TEST(DirectObject.DirectObject):
def __init__(self):

base.disableMouse()

base.setBackgroundColor(0, 0, 0)
self.keyMap = {"d":0,"h":0}

# i changed to mouse controlls
self.accept("d", self.Keys, ["d",1])
self.accept("d-up", self.Keys, ["d",0])

self.accept("h", self.Keys, ["h",1])
self.accept("h-up", self.Keys, ["h",0])

def enemyPOS(i):
return Point3((i%raw)-1, int(i/raw)-1 , 0)

self.enemys = [None for i in range(count)]

for i in range(count):

self.enemys[i].reparentTo(render)
self.enemys[i].setScale(.2,.2,.2)
self.enemys[i].setPos(enemyPOS(i))

self.player = Actor("player")
self.player.reparentTo(render)
self.player.setScale(.2,.2,.2)

camPOSy = self.player.getY()+30

base.camera.setPos(3.5,camPOSy,10)
base.camera.setHpr(180,-20,0)

self.startTIME = 1
#just for your tests- press s to rotate

if self.keyMap["h"]:
XX = task.time - self.startTIME *33
self.player.setHpr(10*XX,0,0)

def Keys(self, key, value):
self.keyMap[key] = value

if self.keyMap["d"]:

self.proj = [None for ii in range(count)]

for ii in range(count):

self.proj[ii].reparentTo(render)
self.proj[ii].setScale(.2,.2,.2)

self.proj1.reparentTo(render)
self.proj1.setScale(.2,.2,.2)

playerH = self.player.getH()
playerP = self.player.getP()

X =self.player.getX()-.15
Y =self.player.getY()
Z =self.player.getZ()-0.6

X1 =self.player.getX()+.15
Y1 =self.player.getY()
Z1 =self.player.getZ()-0.6

self.direction1 = self.player.getHpr()

self.proj[ii].setPos(X,Y,Z)
self.proj[ii].setHpr(self.direction1)

self.proj1.setPos(X1,Y1,Z1)
self.proj1.setHpr(self.direction1)

fireX = LerpPosInterval(self.proj[ii], 500,Point3(0,-100,0), other = self.proj[ii])
fireX.start()
fireX2 = LerpPosInterval(self.proj1, 500,Point3(0,-100,0), other = self.proj1)
fireX2.start()
fireX1 = LerpColorInterval(self.proj[ii], 30, Vec4(0,0,1,1), Vec4(1,.5,0,1))
fireX1.start()
fireX3 = LerpColorInterval(self.proj1, 30, Vec4(0,0,1,1), Vec4(1,.5,0,1))
fireX3.start()

for i in range(count):

self.enemys[i].setScale(.2,.2,.2)
disPROJ = self.proj[ii].getPos() - self.enemys[i].getPos()
disPROJlength1 = disPROJ.length()

if (disPROJlength1 < 1):
print "HIT"
self.enemys[i].hide()

X=TEST()
run()``````

You donāt loop over ii in projINTERACTION. Actually ii seems not to be defined at all. This should give you an errorā¦

the code tags!

i changed form the distance measuring to a collision recallā¦

thx for all the help

``````# weapons drh 2008

import direct.directbase.DirectStart
from direct.showbase import DirectObject
from direct.interval.IntervalGlobal import *
from pandac.PandaModules import *

count = 100
BULLETScount = 500

COLORintervalTIME = 30
cTrav1 = CollisionTraverser()

class WEAPON(DirectObject.DirectObject):
def __init__(self):

base.setBackgroundColor(0, 0, 0)
self.keyMap = {"d":0,"h":0}

self.accept("mouse1", self.Keys, ["d",1])
self.accept("mouse1-up", self.Keys, ["d",0])

def Keys(self, key, value):
self.keyMap[key] = value

for i in range(count):

if self.keyMap["d"]:

proj = [None for ii in range(count)]

proj[ii].reparentTo(render)
proj[ii].setScale(.2,.2,.2)

###
###COLLISION
###

projENEMYRay = CollisionRay()
projENEMYRay.setOrigin(0,0,100)
projENEMYRay.setDirection(0,0,-1)

projENEMYCol = CollisionNode('projRay')

projENEMYColNp = proj[ii].attachNewNode(projENEMYCol)
projENEMYQueue = CollisionHandlerQueue()

cTrav1.showCollisions(render)
projENEMYColNp.show()

###

self.proj1.reparentTo(render)
self.proj1.setScale(.2,.2,.2)

proj[ii].setPos(X,Y,Z)
proj[ii].setHpr(self.direction1)

self.proj1.setPos(X1,Y1,Z1)
self.proj1.setHpr(self.direction1)

fireX = LerpPosInterval(proj[ii], BULLETScount,Point3(0,-100,0), other = proj[ii])
fireX.start()
fireX2 = LerpPosInterval(self.proj1, BULLETScount,Point3(0,-100,0), other = self.proj1)
fireX2.start()
fireX1 = LerpColorInterval(proj[ii], COLORintervalTIME, Vec4(0,0,1,1), Vec4(1,.5,0,1))
fireX1.start()
fireX3 = LerpColorInterval(self.proj1, COLORintervalTIME, Vec4(0,0,1,1), Vec4(1,.5,0,1))
fireX3.start()

for i in range(projENEMYQueue.getNumEntries()):
entry = projENEMYQueue.getEntry(i)
point = entry.getSurfacePoint(entry.getIntoNodePath())
#point1 = entry.getSurfacePoint(getFromNodePath())