[英]Pickle is saying it can't pickle a pygame.surface, but my object isn't a pygame.surface
Basically, I am trying to pickle a class called State, which holds the game state that I want to send over, which does not contain any pygame.surfaces. 但是酸洗是说我试图用这个错误来酸洗一个:TypeError: cannot pickle 'pygame.Surface' object。 这是我的 state class:
class State():
def __init__(self):
self.choosen = [None,None,None,None,None,None,
None,None,None,None,None,None];
self.Won = None;
self.tile = [0,0,0,0,0,0,
0,0,0,0,0,0]
self.level = 1;
self.pnum = [0,0];
self.pCards = [[],[]];
self.ready = False;
self.turn = False;
这不包含 pygame.surface。 此处列出了其他相关代码段。
这就是服务器发送信息的方式。 我在上面声明了套接字。
def threaded_client(conn,player):
global pnum
conn.send(pickle.dumps(player));
reply = None;
while True:
try:
data = conn.recv(4096)
state = pickle.loads(data);
if not data:
print("Disconnected");
break;
else:
reply = state;
print(pnum);
state.ready = pnum == 2;
conn.sendall(pickle.dumps(reply));
except:
break;
这就是我的网络 class 发送信息的方式。
def send(self,data):
try:
self.client.send(pickle.dumps(data))
p = pickle.loads(self.client.recv(4096));
return p
except socket.error as e:
print(e);
谢谢!
编辑:我发现了问题,选择的数组是图像。 其中之一是一旦你提出问题,你就会更加努力地检查你的代码以找到相当明显的东西。
你有这一行:
conn.send(pickle.dumps(player));
尽管您没有显示player
的定义,但由于这是 pygame 的东西,我将假设它是 Sprite。 如果是,那么它将有一个self.image
属性,即 Surface。 这很可能是投诉的来源。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.