functool - partial errors - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: functool - partial errors (/thread-17867.html) |
functool - partial errors - SheeppOSU - Apr-27-2019 I am making a game - I didn't put it in Game Development because this is just about functools - and I have this button that I give a function for one of the paramters. TIA for you help. This one works - SpikeBatBT.optClick(gD, blue, lighter_blue, partial(giveItem, args=(SpikeBat)))Why doesn't this one - SlotBtn.optClick(partial(self.equipChange, args=(False, self.equips + (n,))))Error - BTW they both use different functions. One is an invisible button whilst the other is a visible button.If you need it - Function for the top one - class Button(): def __init__(self, rect, text, textsize, textcolor): self.rect = rect self.font = pygame.font.SysFont('arial', textsize) self.textSurf, self.textRect = Screen_Display.text_objects(text, self.font, textcolor) self.textRect.center = ((rect[0] + (rect[2]/2), rect[1] + (rect[3]/2))) def draw(self, gD, ButColor): pygame.draw.rect(gD, ButColor, (self.rect)) gD.blit(self.textSurf, self.textRect) def optClick(self, gD, ShadowColor, ButColor, command=None, command2=None): mouse = pygame.mouse.get_pos() click = pygame.mouse.get_pressed() if self.rect[0] + self.rect[2] > mouse[0] > self.rect[0] and self.rect[1] + self.rect[3] > mouse[1] > self.rect[1]: pygame.draw.rect(gD, ShadowColor, (self.rect)) gD.blit(self.textSurf, self.textRect) if click[0] == 1: if command != None: command() if command2 != None: command2() else: pygame.draw.rect(gD, ButColor, (self.rect)) gD.blit(self.textSurf, self.textRect)Invisible Button - class InvisButton(): def __init__(self, rect): self.rect = rect def optClick(self, command=None, command2=None): mouse = pygame.mouse.get_pos() click = pygame.mouse.get_pressed() if self.rect[0] + self.rect[2] > mouse[0] > self.rect[0] and self.rect[1] + self.rect[3] > mouse[1] > self.rect[1]: if click[0] == 1: if command != None: command() if command2 != None: command2() Full code if you need it - https://github.com/Sheepposu/Destination RE: functool - partial errors - rxndy - Apr-27-2019 I recommend using argument names: for example func1(arg1="tomato", arg2=partial(blehbleh)) This may help because you may be passing partial to the wrong argument/parameter. |