This is probably an easy problem to solve but I'm having a bit of difficulty. The error is UnboundLocalError: local: "switch" and that's all the error says. The line refers to the line switch = - switch in the following code:
boundary = game.getBoundary()
game.setBackground(java.awt.Color.black)
level = 1
maxX = -1
maxItem = 0
minX = boundary.getWidth()+1
minItem = 0
change = 0
switch = 1
class shootCollisionListener (events.CollisionListener):
global switch
def __init__ (self, item):
self._item = item
def collisionDetected(self, event):
if(event.getSource()==boundary):
switch = -switch
elif(event.getSource().getType()=="projectile"):
game.removeElement(event.getSource())
game.removeElement(self._item)
I used global so I don't know why I'm getting this error.