我正在尝试在 PyGame 中制作多人游戏。到目前为止,所有玩家都在
pygame.Rect
。
不过,为了让播放器更加灵活我创建了一个播放器类:
import pygame
from scene import load_player_entry
import values
class Player(pygame.Rect):
def __init__(self, username, color, scene):
self.name = username
self.color = color
self.scene = scene
super().__init__(load_player_entry(self.scene), (values.PLAYER_WIDTH, values.PLAYER_HEIGHT))
def set_scene(self, scene):
self.scene = scene
self.x, self.y = load_player_entry(self.scene)
问题是,当我“pickle”对象并通过套接字将其发送到另一个客户端时,我收到以下错误:
TypeError: Player.__init__() takes 4 positional arguments but 5 were given
我已经尝试过使用普通的泡菜和莳萝,两者都有同样的问题。 将缓冲区大小增加到 8192 也不起作用。
如何解决这个问题?任何帮助将不胜感激
看起来你在调用类时有 1 个无用的参数。例如:
class Foo:
def __init__(self, a, b, c):
print(a, b, c)
正确调用:
bar = Foo(1, 2, 3)
不正确的调用(4是无用的参数):
bar = Foo(1, 2, 3, 4)
或者,如果您解压列表,例如:
my_list = [1, 2, 3, 4] # list len is more that args count
bar = Foo(my_list*)