I've been trying to make a text-based game and figured that I probably need a saving system. This is what I've done so far:
class Player:
def __init__(self, health, defence, att, inventory, money, name):
self.health = health
self.defence = defence
self.att = att
self.inventory = inventory
#set the inventory as a list and add items to it
self.money = money
def strike(self, enem):
...
def addtoinv(self, item):
...
Here's a snippet of my code that makes the Player class.
Player = Player(20, 5, 0, [], 0)
Here I'm making the player object.
f = open("save_file.dat", "wb+")
pickle.dump([Player], f)
And here is where the issue occurs. I'm trying to serialize the object and save it to a file but instead it throws this error:
_pickle.PicklingError: Can't pickle <class '__main__.Player'>: it's not the same object as __main__.Player