I keep having the error
UnboundLocalError: local variable 'new_speedDx' referenced before assignment
while trying to run the following function:
def new_speedD(boid1):
bposx = boid1[0]
if bposx < WALL:
new_speedDx = WALL_FORCE
elif bposx > WIDTH - WALL:
new_speedDx = -WALL_FORCE
bposy = boid1[1]
if bposy < WALL:
new_speedDy = WALL_FORCE
elif bposx > WIDTH - WALL:
new_speedDy = -WALL_FORCE
return new_speedDx, new_speedDy
In this function, boid1 is a vector with 4 elements (xpos, ypos, xvelocity, yvelocity) and all variables in upper case are constants (numbers). Anyone got an idea how to solve this? I've found many possible solutions on the internet but nothing seemed to work..