import bgeimport pickle
cont = bge.logic.getCurrentController()
own = cont.owner
dat = own['check']
f = open('store.txt', 'wb')
pickle.dump(dat, f)
f.close()
own['check'] = dat
There aren’t any syntax errors in the console, but the variable doesn’t save… Can someone tell me how to fix this? I plan to use it to save a variable so I tell something in a different part of the game.
A lot of people use with instead of file these days, maybe read up on it if you want to keep up to date (this is an old code snippet). You should also check out expand path if you’re not already using it.
The BGE provides a method to refer to the path where your startup-Blend-file is located. You do that with “//”.
But this is BGE-syntax not Python syntax. So you need to let the bge parse the path string you provide before you use Python libraries on it. The conversion is done by bge.logic.expandPath.