Saving progress | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Saving progress

now i'm working on a game with python and it's working just fine .. it just needs a code to save the progress that the gamer made , so the next time he playes he don't have to start from the beginning .. how can i do it ?!

16th Dec 2016, 9:26 PM
ahmed mohamed
5 Answers
+ 2
You know how to read from and write to files in python? If not , just complete the python course here first. Then say suppose you want to save the following data in file noOfLives: 3; playerName: "Yash"; score: 33; ... You can simply store "3 yash 33" in a file using file I/O and later when you load it you know the first value is for noOfLives, 2ndfor name,etc. This is the most basic way. Good enough for a beginner. if you want advanced methods then there are also modules like 'pickle' to serialize data and store a JSON structured data in a file. which could look like: { noOfLives: 3, playerName: "Yash", score: 33, cells=[2,3,4], time:50 }
16th Dec 2016, 10:14 PM
Caffeinated Gamer YT
Caffeinated Gamer YT - avatar
+ 2
The way I would do it, is to create table in some datebase and search how to connect that database with python. You will need to go through SQL course for this.
17th Dec 2016, 2:43 AM
Majstor_Gile
Majstor_Gile - avatar
+ 1
Simplest way is to save your game data to a local file with File I/O functionality. Later load it back. You will also need to define a standard format for the game data for saving and loading.
16th Dec 2016, 9:34 PM
Caffeinated Gamer YT
Caffeinated Gamer YT - avatar
0
can you explain more please
16th Dec 2016, 9:38 PM
ahmed mohamed
0
sorry but what does ( File I/O ) stand for or mean excactly ?
17th Dec 2016, 7:49 AM
ahmed mohamed