1

Hi all I am creating a game that allows the user to export their progress to another file which can be loaded back up again once they come back. I am wondering if there is a way to export multiple variables to a different file, which will then change the file in the computer's memory. I have a way to import the variables, I just need some help with the exporting part, thank you for your help, Darren.

2
  • Save to a JSON or Pickle file, and have the other script load from the file. Commented Mar 2, 2022 at 23:06
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Mar 2, 2022 at 23:32

1 Answer 1

1

You can try store the users progress data in JSON file. In python it`s pretty easy, you just need to use json library.

First you should import lib

import json

For example the player`s data looks like this

player_data = {
    'username': 'Nemo',
    'xp': 1000,
    'armor': {
        'name': 'Kaer Morhen armor',
        'weight': 1.57
    }
}

Than you can easely export this data to JSON file

with open("data_file.json", "w") as wf:
    json.dump(player_data, wf)

And import it back

with open("data_file.json", "r") as rf:
    player_data = json.load(rf)

I hope it would be helpful for you :)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.