Saving Games in Python
So, I need help with a function in my game, Stormfront.
Basically, I need a simple way of saving my game using a specific keyword. Is there any answer to my question?
< Umar Qureshi >
The easiest way is just to use replit db.
You can save a key like this:
and then get the value of a key
An example would be saving a dictionary holding the user data
You could also use a txt file and use json to retrieve the files.
f = open("hello.txt", "w") # "w" will always overwrite the file
f.write("Hello Text File!")
f = open("grocery.txt", "r")
text = f.read() # this gives us everything back at once
Then use json to get the data back.
To append use "a" in open("hello.txt", a)
@UmarQureshi4 maybe you could use the replit database and ask the user their username, and when they're done, save their progess by assigning the key, username, to a value, their progress. you can see how to use the replit database at https://docs.replit.com/tutorials/11-using-the-replit-database