Posts: 26
Threads: 7
Joined: Sep 2022
Hello,
I am making a game with python and the content is expanding really fast. It's beginning to reach the point that it can't be played in one sitting. How do I make a game save?
The data is stored in variables. For example, I have a variable named AmountOfWood.
How do I make these save?
The only stupid person in the world, is the person that doesn't ask questions.
-Someone smart
Posts: 453
Threads: 16
Joined: Jun 2022
(Oct-04-2022, 11:53 AM)Gribouillis Wrote: ... you could use a "shelve" like in this blog post.
Thank you for the link. I had been reading about how to create a text based adventure game, which Al Sweigart also has on his site, which is one of the best guides I've seen. The system that he's developed is very good and makes the process very easy to maintain: easy to test, easy to add rooms and objects; just an excellent system.
What I now have is not verbatim, but it's 90% based on what I found at The Invent with Python Blog -- highly recommended.
Sig:
>>> import this
The UNIX philosophy: "Do one thing, and do it well."
"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse
"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
Posts: 26
Threads: 7
Joined: Sep 2022
(Oct-04-2022, 01:14 PM)snippsat Wrote: TinyDB is also an easy option for this.
Example.
from tinydb import TinyDB, Query
db = TinyDB('score.json')
# Insert score
score = dict(AmountOfWood=33)
db.insert(score)
# Overwrite score
#db.update(score)
# Clean all
#db.truncate()
Test it out.
>>> db.all()
[{'AmountOfWood': 33}, {'AmountOfWood': 55}, {'AmountOfWood': 99}]
>>> # Find max score
>>> max(item['AmountOfWood'] for item in db.all())
99
If only want last score to be saved use db.update
I tried to use that, it just says
Traceback (most recent call last):
File "C:\Users\Wannes\survival spel 1.5 klad.py", line 2, in <module>
from tinydb import TinyDB, Query
ModuleNotFoundError: No module named 'tinydb'
Which states there is no tinydb. How do I fix this?
The only stupid person in the world, is the person that doesn't ask questions.
-Someone smart
Posts: 453
Threads: 16
Joined: Jun 2022
(Oct-06-2022, 08:29 AM)BliepMonster Wrote: ModuleNotFoundError: No module named 'tinydb'
Which states there is no tinydb. How do I fix this?
The first question has to be: did you
pip install tinydb
?
Sig:
>>> import this
The UNIX philosophy: "Do one thing, and do it well."
"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse
"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein