Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Looking to Save Data
#1
I'm very new to both Python and this forum, so please forgive me if I don't include all the information needed or I've posted in the wrong place.

I am trying to make a game, which I suspect is pretty common. A friend of mine walked me through some of the basics and I was able to create a simple procedural generator that designs planets. It is essentially a mad lib that the program fills in itself with the random module and some lists. I want to use that program as a sample for a jumping off point, though this is now an old project and I'll probably use what I learn from here to make something else.

Anyway, to give an idea of where I am coming from I would have to state that my inspiration was the Legends mode of Dwarf Fortress. I loved how these complex, and at times ridiculous, stories would evolve in that game's generator and I would sometimes create new games just to read these stories. With that said I am trying to take that planet generator, or whatever I end up making that is similar, and allow the program to save each planet it creates and even develop entire systems, using those planets, that the user can then access like a reference library and read the descriptions. I would also like to be able to save all that procedurally created content so the user could close down the program, open it back up, and load all that back up or even another save file if you make multiple saves.

The question is, how would I do that? I've lost contact with my programmer friend a while back, for reasons I'm unsure of, so I can't ask him. I've tried looking it up and have slogged through multiple posts and videos, all of which I'm unsure ever gave me the answer I was seeking.

I'd appreciate any help anyone could give in pointing me in the right direction, at the very least, and I would be glad to provide any information you may need.
Reply
#2
How you would do the export (saving) is secondary question and it will depend on the answer of the first question - what (i.e. what kind of data) you want to export and in what format. I am not familiar with the the game you refer to, but quick look at the wiki, suggest that there are two types of information - textual (incl. some configuration options) and visual (images/maps). So I guess your game will have something similar will be in your game, right?

some options (not exhaustive list) - you can export text information as json file or xml file (xml is what the other game uses).
same for config options or you can use "native" config file support in python.
images/maps - as image files (e.g. jpg) or you can convert image to string and save it as text information (see above). Of course you have to implement also the reverse process.
That is if you want to use plain text files. As an alternative you can use database (e.g. SQLite) or some of the other options for object serialization in python like pickle.
I know this is very broad answer but it's also true for your question.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
To add to @buran's post. Keep it simple. The game configuration should not be in the same file as the player's config info. For example.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#4
Thanks for the responses so far! I appreciate any help I can get...

In my search I've found someone explaining the pickle module, but he made it seem as though that was for very light data, like serial numbers. Would that work with saving and loading the plugged-in generator text data? If so, I might be able to get to work on that right away!

Don't worry about map image generation. I'm working with text only. Trying to keep it simple for my first project, even though it is still pretty complicated for me, it seems. Haha!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how to save to multiple locations during save cubangt 1 554 Oct-23-2023, 10:16 PM
Last Post: deanhystad
  Save data frame to .csv df.to.csv() mcva 1 1,534 Feb-03-2022, 07:05 PM
Last Post: mcva
  SaltStack: MySQL returner save less data into Database table columns xtc14 2 2,167 Jul-02-2021, 02:19 PM
Last Post: xtc14
  How to save json data in a dataframe shantanu97 1 2,159 Apr-15-2021, 02:44 PM
Last Post: klllmmm
  sqlite3 database does not save data across restarting the program SheeppOSU 1 3,451 Jul-24-2020, 05:53 AM
Last Post: SheeppOSU
  How to save Python Requests data sent to server? RedLeonard 5 4,976 Jul-05-2020, 10:33 AM
Last Post: RedLeonard
  How to save CSV file data into the Azure Data Lake Storage Gen2 table? Mangesh121 0 2,113 Jun-26-2020, 11:59 AM
Last Post: Mangesh121
  Save Arduino data in mysql server via raspberrypi rithikvg 1 3,404 Jun-24-2020, 10:59 PM
Last Post: Larz60+
  Why does Python/gpx save data as Latin1? Winfried 2 2,394 Nov-12-2019, 03:59 PM
Last Post: Winfried
  save data in .txt after certain interval Shaswat 1 2,099 Oct-13-2019, 07:07 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020