Save and Load organized

I am developing a horror game that will save when I have completed a task.
And it will load when it starts.
This is pretty basic and easy to find, but what I want is something more organized, that doesn’t create a bunch of files and doesn’t stay in the folder where the game is.
I don’t really like the game creating a Save file inside the folder where it is and even if you like it, in the final version it won’t work!

I found the save of a game I like, the name of this game is FNAF World and it has a Save file of a cute and organized geito.


This is how I wish it was my Save file.

1 Like

You should store all your variables in a dictionary, and then write them in json format. BGE has a global dict thing that does something like that and you can write it to a file and it’s encoded so the file cant be modified manually

1 Like

Can you explain to me in more detail? please?

The save file you pictured appears to be in config file format. For information on how to parse config files see here. Json is a little more powerful, but also harder to use. Information on json in Python can be found here. I personal found this json tutorial to be usefull. Note that both of these will require Python scripting. I don’t know if it is possible to save and load with nodes.

1 Like

ok, but I don’t know how to program in Python.

Here is my version:

1 Like

thank you very much :+1:

You’re right to be concerned; the folder that your game gets installed to won’t have write access.
There are three ‘standard’ places to store save data in Windows:

  1. %homepath%
    This is your users home directory. If you store your data here then only that specific Windows login will be able to access it. This can be useful if you want different Windows logins to have their own progress saved in your game.
  2. %programdata%
    This folder is the same for all users. HOWEVER, you need to be careful with permissions. By default, any file written will be read/write for the creator, but only read for everyone else. This is why you often see “Install for all users” as an option inside installers.
  3. %appdata%
    Pretty similar to %homepath%, but less visible to the user.

Please please please don’t store save data in the registry.

By the way, paths like %homepath% are called “environmental variables”. They point to specific folders on the computer that have been set up with a specific purpose in mind. The user may move them (but usually shouldn’t). Try opening up the run dialog (windows key + R) then putting in %homepath%.

You should use %localappdata% instead

And keep in mind this only works on windows OS.

Practically I don’t think it makes any difference. I can see my installed programs are roughly half split between the two.

Yep, that’s why I put it in my second sentence.

Everything is working normally, there is nothing wrong.
but the only problem is this Username, because I think it will only work on my computer if I put the name of my computer and that’s the problem.
image
can you help me with this?

Make Username a variable -

NAME = ‘’
‘C:/Users/’ + NAME + ‘/AppData/Roaming/.Moonlight/Saves/’

Make a menu option for users to enter their USERNAME & set that text-input to variable NAME.

I want to put the computer name.
And the players are not going to like it all that much.

1 Like

So . . . You want to know how to do this? :thinking:

1 Like

Yes, that’s right

1 Like

%localappdata% won’t work in this case

instead use this:

path    = os.environ['LOCALAPPDATA'] + '/Game_name/Saves/'
2 Likes

thank you very much

1 Like

Script fully set-up to display computer name in Console & Text object
Print_Computer_Name.blend (105.9 KB)

Function socket.gethostname()

import socket

def main():

print(socket.gethostname())

main()

1 Like

if you need only the name for some reason (i think not) then use

print(os.getlogin())

to print the username that has been logged in

@RPaladin
no need to call a socket, use the os module

1 Like

Yeah, I had limited time & couldn’t find it in the os module so I went with the socket one :slight_smile: