I am making a text RPG in Python 3.4.0, and I am making save data.
My program can create the file, but when it tries to read the file, it only reads the first line.
How do I make the program so it reads the lines individually and how can I use those lines in my program?
import os.path
import time
import pickle
save_data = open("Text_RPG_save_data.dat", "wb")
load_data = open("Text_RPG_save_data.dat", "rb")
def data_save():
print("Saving progress...")
user_name = input("Enter your username.")
level = str(0)
pickle.dump("user_name = " + user_name, save_data)
pickle.dump("\nlevel = " + level, save_data)
save_data.close()
print("Save successful.")
def data_load():
print("Loading progress...")
loaded_data = pickle.load(load_data)
print(loaded_data)
load_data.close()
print("Load successful.")
def data_delete():
os.remove("Text_RPG_save_data.dat")
data_save()
data_load()
delete_affirm = input("Would you like to delete your progress? Y/N")
if delete_affirm == "Y":
data_delete()
time.sleep(5)
if delete_affirm == "N":
time.sleep(5)
Current results:
Loading progress...
user_name = Foo
Load successful.
Expected results:
Loading progress...
Welcome, Foo! You are currently level 0.
Load successful.