I am developing a game with python 3.6, I want in its multiplayer version to send to the server objects modified by the client ( the player) I thought to serialize them for transfer. I use pygame and thus pygame.Surface in my objects
I have objects with this structure:
class Cargo(Bateau):
dictCargos = dict()
def __init__(self, map, nom, pos, armateur=None):
Bateau.__init__(self, map, nom, armateur, pos)
self.surface = pygame.image.load(f"images/{self.nom}.png").convert_alpha()
self.rect = self.map.blit(self.surface, self.pos)
...
Cargo.dictCargos[self.nom] = self
When I serialize another object without pygame instance it's ok But with the object described above I get this error message:
import pickle as pickle
pickle.dump(Cargo.dictCargos, open('file2.pkl', 'wb'), protocol=pickle.HIGHEST_PROTOCOL)
Traceback (most recent call last):
File "./pytransit.py", line 182, in <module>
encreG(joueur, event)
File "/home/patrick/Bureau/PyTransit/modulesJeu/tests.py", line 25, in encreG
pickle.dump(Cargo.dictCargos, open('file2.pkl', 'wb'), protocol=pickle.HIGHEST_PROTOCOL)
TypeError: can't pickle pygame.Surface objects
Do you have any idea how to transport these items to the server. Or bypass this pickle restriction?
The same problem would arise if I wanted to save a part, so save these objects