I'm new to this forum and to python in general, so be easy on me please. :icon_smile:
I'm making a class to handle all events including mouse events. (I'm using pygame by the way)
Heres how it looks so far:
class Event: #controlls all actions relating to events including #mouse events def __init__(self): #mouse vars self.mouse_p = [0,0,0] #previous pressing state of buttons self.mouse_a = [0,0,0] #whether the buttons are pressed self.mouse_t = [0,0,0] #time the buttons are pressed self.mouse_c = [0,0,0] #whether buttons are clicked (in that step) self.mouse_r = [0,0,0] #whether buttons are released def step(self): pygame.event.get() self.mouse_a = list(pygame.mouse.get_pressed()) print self.mouse_a for i in range(3): if (self.mouse_p[i] == 0)and(self.mouse_a[i] == 1):#mouse active self.mouse_c[i]=1 else: self.mouse_c[i]=0 if (self.mouse_p[i] == 1)and(self.mouse_a[i] == 0):#mouse released self.mouse_c = 1 else: self.mouse_c = 0 if(self.mouse_a[i]==1): #mouse time self.mouse_t[i] +=1 else: self.mouse_t[i]=0 self.mouse_p = self.mouse_a
The problem is, when I test it, "self.mouse_c=0, TypeError: 'int' object does not support item assignment" comes up. I really don't know why this is. I assume that the lists are immutable inside the "step" method, but why would this be: why wouldn't it have full access to its own variables?
The only way I can think of solving this this to replace each list in one go rather than trying to set the values of each index of the list... but surely there is some other way.
If you could help, it would be greatly appreciated!