# Help with a error..

Hi people, i’m developing a penalty kick game with panda3d + python, and i have a problem with a colision with the goal…

hi have this code…

Goal:

``````from pandac.PandaModules import *

class Baliza():
def __init__(self, game, name, yPosition):

self.model.reparentTo(render)

self.model.setScale(.025, .05, .03)
self.model.setX(.2)
self.model.setY(yPosition)

self.boundaries = {}
self.addBoundary(name,-370, 0, 250, 370, 0, 250, 10,(1, 0), (-1, 1))

def addBoundary(self, name, X1,Y1,Z1,X2,Y2,Z2,TAM, posOffset, velMultiplier):
boundary = CollisionTube(X1,Y1,Z1,X2,Y2,Z2,TAM)
boundary.setTangible(True)
self.boundaries[name] = [boundary, posOffset, velMultiplier]
colNode = self.model.attachNewNode(CollisionNode('goal' + name))

def collide(self, ball, boundaryName):
vel = ball.body.getLinearVel()
pos = ball.body.getPosition()
b = self.boundaries[boundaryName]
ball.body.setPosition(pos.getX() + b[1][0], pos.getY() + b[1][1], pos.getZ())
ball.body.setLinearVel(VBase3(vel[0] * b[2][0], vel[1] * b[2][1], vel[2]))``````

and in the Game:

``````
(...)

elif fromName == "ballNode":#se for a bola
if intoName == "playerNode":
pass
elif intoName == "goalBlue" or intoName == "goalRed":
self.baliza.collide(self.ball, intoName)

(...)``````

And i have got the error:

``````Traceback (most recent call last):
File "Game.py", line 76, in updateScene
self.baliza.collide(self.ball)
AttributeError: 'dict' object has no attribute 'colide'
Traceback (most recent call last):
File "Game.py", line 100, in <module>
game.run()
File "dstroot/pythoncode/Developer/Panda3D/lib/direct/showbase/ShowBase.py", line 2531, in run
File "Game.py", line 76, in updateScene
self.baliza.colide(self.ball, intoName)
AttributeError: 'dict' object has no attribute 'colide'``````

Anyone can help me? what is this ‘dict’ object??

What is wrong? with the field is working fine…

Thanks a lot.

“dict” is the “type” of a Python dictionary (you use some in the code you have here, they use the curly brackets “{ }”).
So what this error means is you are expecting “self.baliza” to be an instance of your custom class “Baliza”, but instead it is a dictionary.
Probably somewhere in your code there is a line that is setting “self.baliza = something”, where “something” is a dictionary, or a function call that returns a dictionary.

The just thing i have is this on Game constructor:

``````self.baliza = {
"Blue" : Baliza(self, "Blue", 87),
"Red" : Baliza(self, "Red", -90)
}``````

But i cant fix the error, when the ball collide with the goal the game show the same message…

if anyone have ideas i appreciate and thank…

Very thanks…

I see now, it is intended for self.baliza to be a dictionary. In that case you must use give the dictionary a key in order to pick which goal you want to call the “collide” function on.

``self.baliza.collide(self.ball)``

You could do:

``self.baliza["Blue"].collide(self.ball)``

Also check the spelling, in some spots you have “collide” and others “colide”.

Very thanks for helping…

I have a few bugs but is in implementation of the red team and the blue team…

Thanks…

People, i need another help…its confused explain this…but i’m try…

I’m trying to goalkeeper grab the ball for 5 seconds and then kick the ball…

I’m using the task.time to control the time…but i have a problem…

i have 2 classes, GamePlay.py and Keeper.py

on gameplay when the ball touch on the keeper i call the function “defend(task,oldTime)” and then i’m trying to the keeper stay with the ball for 5 seconds…

But with the task.time the time starts at the beginning of the game…

I’m trying save a oldTime where this “oldtime” is when the function “defend()” is called, and compare with the real time…but because of the cycle of the game the the OldTime is updated constantly and is equal to task.time…

The code…Example…
The GamePlay.py

``````elif fromName == "ballNode":# if its a ball
if intoName == "playerNode":
pass
elif intoName == "keeperNode":

The Keeper.py

``````def defend(self,task,oldTime):
pos = self.ball.body.setPosition(self.getX(),self.getY()+2,self.getZ()+2)
self.physics.setGravity(0, 0, 0)

#kick the ball``````

Its possible with this way?

How i can wait 5 seconds and kick the ball??

Thanks all…
André.

When you catch the goalkeeper’s grab you can invoke doMethodLater (using 5 seconds as argument), and you can define the code related to the kick in the called function.

PS You MUST implement the Francesco Totti’s cucchiaio.

Very thanks Yaio…it help me very much…

Thanks,
Andre.