0

I was trying to create a save system for a game I'm creating. I found a simple idea on how to do it using pickle but I came across some problems. First, I had a problem with:

TypeError: write() argument must be str, not bytes

This was easily solved by using 'wb' instead of 'w' but this brought up the problem I have now. I tried looking it up but the answers were too complex for me to deal with or not explained well enough so now I'm stuck with this.

if (Save == "YES"):
    import pickle
    data = {'HP':HP,
          'lvl':lvl,
          'Xp':Xp,
          'BaseAttack':BaseAttack,
          'BaseDefense':BaseDefense,
          'BaseDodge':BaseDodge,
          'Weapontype':Weapontype,
          'Clothingtype':Clothingtype,
          'Weapon':Weapon,
          'Attack':Attack,
          'Clothes':Clothes}

    with open('savefile','wb')as f:
        pickle.dump(data,f)
Load = input("Would You Like To Load YES/NO:, ")
if (Load == "YES"):
    import pickle
    with open('savefile')as f:
        data = pickle.load(f)

Here is the error:

TypeError: a bytes-like object is required, not 'str'

How can I change the file if I can't load it?

Micho
  • 3,929
  • 13
  • 37
  • 40
haha262
  • 1
  • 3

0 Answers0