Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

p5(python port) – TypeError: 'int' object is not callable without Python keywords in variable names

I’m new to coding, it’s been a long time since I last coded,
I did it all of a sudden because of a school assignment.

I know my coding is a terrible code covered in ‘global’, but I’m too noob to fix it, so I gave up.
I’m only going to use this as a demonstration of how it works in school, so it doesn’t matter how it’s coded as long as it works.

I know that this error occurs when I put Python keywords in a variable,
Python keywords in the variable are nowhere to be found no matter how much I look for them.
am i blind?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

line 44, in draw springforceY = -springconst(positionY – headposY) TypeError: ‘int’ object is not callable

#importing module
from p5 import *
import builtins
def exit(): # to fix p5.exit exception(not working)
    builtins.exit()

#initial var
gravity = 20
mass = 15
forceY = 0
forceX = 0
springforceY = 0
springforceX = 0
accY = 0
accX = 0
positionY = 100
positionX = 75
velocityY = 0
velocityX = 0
timeGap = 0.2
headpositionY = 110
headpositionX = 80
springconst = 2
#setup(): initial canvas setting
def setup():
    size(400,400) 
    fill(0)

    
    
#draw(): loop after setup()
def draw():
    global springforceX
    global springforceY
    global velocityY
    global velocityX
    global positionY
    global positionX
    global accY
    global accX
    global forceY
    global forceX
    #calculating
    springforceY = -springconst(positionY - headpositionY) # <<< line 44
    springforceX = -springconst(positionX - headpositionX)
    forceY = mass * gravity + springforceY
    forceX = springforceX    
    accY = forceY/mass
    accX = forceX/mass
    velocityY = velocityY + accY * timeGap 
    velocityX = velocityX + accX * timeGap
    positionY = positionY + velocityY * timeGap
    positionX = positionX + velocityX * timeGap
     
    #showing
    background(255, 255, 255)
    ellipse(200, positionY, 20, 20)
    ellipse(headpositionX - 5, headpositionY - 5, 10, 10 )
    line(positionX, positionY, headpositionX, headpositionY)
    text("gravity : "+str(gravity), (0,40))
    text("mass : "+str(mass), (0,50))
    text("accelrationY : "+str(accY), (0,60))
    text("accelrationX : "+str(accX), (0,70))
    if mouse_button == 'CENTER': # press wheel button to restart
        velocityY = 0
        velocityX = 0
        positionY = 100
        positionX = 75


if __name__ == '__main__':
    run()

>Solution :

If it’s maths multiplication, the code should be

springforceY = -springconst * (positionY - headpositionY) # <<< line 44
springforceX = -springconst * (positionX - headpositionX)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading