0

I'm having a bit of a problem in python. It's not with the syntax or anything like that but, I am making a text rpg. I have a save/load feature within the game using pickle. It works just fine. But the problem is when I load the game, the inventory variable is set back to what I defined it as in the init of the main class. its like this:

            class Main():
                def __init__(self):
                    self.inventory = []

and the load command is in the main class as well. But for some reason when I load the variables with pickle, it resets the inventory to whatever it is set as in the main class. How can I stop this?

  • You could use [JSON](https://docs.python.org/2/library/json.html) for exporting and loading the inventory. – Ericson Willians May 31 '15 at 02:50
  • I'm afraid I don't know how to do that, i'm still fairly new. I'll just look it up. – shane fales May 31 '15 at 02:57
  • [Check this out](http://stackoverflow.com/questions/2259270/pickle-or-json), this question will open up your mind a bit :). – Ericson Willians May 31 '15 at 02:59
  • I'm not much of a pickle user, so I'm not going to answer, but, I personally recommend you to read some [JSON tutorials](http://www.tutorialspoint.com/json/json_python_example.htm). It's not difficult. – Ericson Willians May 31 '15 at 03:10
  • Homework problem? possible duplicate of [Pickle user inputs - Python 3](http://stackoverflow.com/questions/30550657/pickle-user-inputs-python-3) – Mike McKerns May 31 '15 at 10:52

0 Answers0