SOLVED - Where is global dictionary saved in a published app?

Hello,

I am developing my game in Blender. I can not find where the globalDict is saved.

But when it is published, the user will most likely not have Blender installed. So if my game uses globalDict, where is this going to be saved ? I think it matters then, because I do not want to create files outside the game’s directory.

Thanks!

PS: I would also want to know where it is stored during development, because I have to code what happens if the cofnig file is not found (default it somehow). However to test this I need to be deleting it.

Can’t you find it in the same directory your current blend file is? It’s named as ‘BlendFileName.bgeconf’.

I recommend saving your globalDict manually though, as you can change the target file where to save.

from bge.logic import expandPath, globalDict
from ast import literal_eval

def save(file_name):
	# file_name can be a relative path, like "saves/file.txt"
	# directory must exist in this case
	try:
		with open(expandPath("//" + file_name), "w") as opened_file:
			opened_file.write(str(globalDict))
			print("Data saved in", opened_file.name)
			
	except:
		print("Could not save", file_name)

def load(file_name):
	
	loaded_data = None
	
	try:
		with open(expandPath("//" + file_name), "r") as opened_file:
			loaded_data = literal_eval(opened_file.read())
			print("Data loaded from", opened_file.name)
			
	except:
		print("Could not open", file_name)
	
	if loaded_data is not None:
		globalDict.update(loaded_data)
		
def main(cont):
	
	sensor_save = cont.sensors["sensor_save"]
	sensor_load = cont.sensors["sensor_load"]
	
	if sensor_save.positive:
		save("my_file.txt")
	
	if sensor_load.positive:
		load("my_file.txt")
1 Like

At the same location as your .blend file, the globaldict file would be called your_blend_name.bgeconf
if you want to save it somewhere else, look at my save and load.

Hello guys,
yes it is Filename.bgeconf,

however I can not see it in Windows 10. I have checked “show file extensions” and “show hidden files”, but it does not show. The file is there thoguh, because when I save incremental, it does not find it the first time. Then the code creates a default conf file and it gets accessed fine.

use the save globaldict brick, and upon loading use the load brick, else you arent saving, and during runtime it’s just a place holder. Once blender closes, the GD is gone too unless you save it.

Thanks, that has been very helpful!

Just a note though, the python version works Ok in another computer at school (I am a school teacher). (Python only, the .conf file is visible and persistent between Blender sessions).
So the same .blend file behaves differently between two computers, both of which have Windows 10, Blender 2.78. Why would that be ?

you use @joelgomes1994 script?

Well i guess that your school PC doen’s have admin rights, so probably the file can’t be saved.
and if you use his version, you get a .txt as save file not a .bgeconf file.

No, I just use saveGlobalDic() for the time being. I have not researched the whole thing yet.

Actually it is the other way around…
I just brought the game to school to show my students and saveGlobalDict() actually works in a computer withOUT admin rights (student’s limited account, Windows 10) (the conf file is visible and persistent between sessions).

At home where I develop in my own laptop with admin rights, it does not work (the conf file is not visible and is not persistent between Blender session, like you described).

It is strange, I will look into it.

So using the script from @joelGomez1994 above will work in any case ? I have yet to try it.

That is strange, it should work on every OS/PC.

Well in theory the script should be working everywhere but again same as bricks, it should work as well. But i’m not happy with the above script due to the try/except functions. Depending on what you want, i also have a save and load in the resources with a bit more options then the script above.

All i can say is: go ahead and try some until you find the one you like the most/works the best for you.

I think it is because I develop my game in a Dropbox folder, and perhaps the file being created at runtime makes some delay to Dropbox to actually see the file, I don’t know, it’s the only explanation I have because today after a restart and forgetting the laptop on for a few hours, suddenly the conf files appear and work fine. I had not changed anything in the game code (which uses saveGlobalDict() python function), nor the account (which is and was admin rights).

Anyway I will mark this as closed for now, because things are like Cotaks and @joelGomez1994, thanks to all of you !