We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, I'm working on a Physics engine with POO (Python Object Oriented). I have an object problem with a certain "call" attribute.
I have a main file and a file called Physics.py. In Physics.py, I have 3 classes: Object, Vector and Rigidbody.
This is the essential properties of my Object class:
class Object:
def __init__(self, x, y, m):
self.rigidbody = Rigidbody(x, y, m)
self.s = 10
This is the essential properties of my Rigidbody class:
class Rigidbody:
def __init__(self, x, y, m):
self.x = x
self.y = y
self.m = m # m is unused yet...
self.velocity = Vector(0, 0)
self.force = Vector(0, 0)
self.acceleration = 1
def initVelocity(self, x, y):
self.velocity = Vector(x, y)
def force(self, x, y):
self.force = Vector(x, y)
This is the essential properties of my Vector class:
class Vector:
def __init__(self, x, y):
self.x = x
self.y = y
self.l = sqrt(x**2+y**2)
Behind, I have functions like self.display() that displays a vector or an object on the screen with basic drawing functions. Finally, here is my main file:
from Physics import *
obj = Object(640, 360, 1)
def setup():
size(1280, 720)
frameRate(60)
smooth()
global obj
obj.defSize(50)
obj.defColor([255])
def draw():
global obj
background(50)
obj.rigidbody.force(100, 0)
obj.display() # This is the display function that I told higher
The force object in the class Rigidbody has other things, but this line in the object is the source of this error:
AttributeError: Vector instance has no attribute '__call__'
When the error comes, Processing highlights this line of code:
obj.rigidbody.force(100, 0)
which is in the def draw(). But when I print callable(Vector) it writes True! I don't understand why I have to add an attribute call to my class, because in my def force(self, x, y), I define the self.force as a Vector object! Is there a problem? Am I calling the Vector instance as a function? Please, I need help! [-O<
Answers
Wait, it was just a name problem... I choose the same name for the function force and the self.force property... I renamed the function addforce and it works!
Oops! You've already solved it 20 min ago. I was too l8! :\">
xD