2

I'm working on a solo adventure RPG console game, similar to a MUD but with no Multi-user.. so a D... I'm trying to save the current function the player is in so that they can load their save.

something like:

def Save()
    save = open("Save.txt", "w")
    save.write(func)
    save.write(Player_Name)

    # etc.

so that on the main screen they can choose load and the code would read:

def Load()
    load = open("Save.txt", "r")
    Func = load.readline()
    Player_Name = load.readline()

    # etc.

and then after it reads the doc it loads the correct function for where they are in my game (each chapter has its own function)

any assistance on how to make this work would be awesome!

thanks guys (and gals)

user94559
  • 59,196
  • 6
  • 103
  • 103
  • 3
    You're actually looking for pickling. Read the doc [here](https://docs.python.org/3/library/pickle.html). [Here](http://stackoverflow.com/questions/20716812/saving-and-loading-multiple-objects-in-python-pickle-file) is an example. – idjaw Oct 04 '16 at 02:46
  • Is there a way to save the calling function as a string to a txt file. My script isn't set up for pickling lol! It's a mess to be honest but it works. At the moment I'm using a counter that changes on each chapter then a mile long elif function like if capt == 1: capt1() elif capt == 2: capt2() – Shannon -ThymeTheory- Green Oct 04 '16 at 03:35
  • I still think pickling is a good option. But if all you are looking for is just the name of the method, then: `save.write(func.__name__)`. Get acquainted with the different attributes types available. [Here](https://docs.python.org/3/library/stdtypes.html?highlight=__name__#definition.__name__) is the documentation – idjaw Oct 04 '16 at 03:54
  • Thanks mate. I'm going to rewrite it to pickle later but as it stands I can't really be bothered lol as for loading the function just calling save.readline() won't load the right method will it? Lol – Shannon -ThymeTheory- Green Oct 04 '16 at 04:01
  • Hmm maybe I'll recode for pickling after all. This is more hassle then it's worth lol!! Thanks for all your help!! – Shannon -ThymeTheory- Green Oct 04 '16 at 05:00

0 Answers0