Exporting/importing Global list to .sav?

Is there a way to export/import the global list to a . sav, or some easy to use script, ideal for saving RPG’s (multiple variables)?

Blendenzo has a tutorial:

That’s not the best way to do what you want, but it should provide you with the basics of using file objects. I recommend that after figuring out blendenzo’s tutorial, you read over the following:


It’s much better to save the data structure itself, then to do the whole readline() juggle. Actually, I think someone should ask Blendenzo to rewrite his tut with those points in mind.

PS: Just for future reference, and for anyone else who might not know yet: Python documentation may not look it, but it is very, very relevant to BGE python. That is to say: Almost any method you see in the python docs should work in the BGE.

A word of warning: I did a save/load system for the new Zark game, and it was ultimately the biggest headache imaginable. I hope to never deal with such a thing again.

Ok. so i can save the files fine (I checked in word pad), but i can’t load it. my script looks like this

loadGame. = open(“LAK.sav”, “r”)
header = readline()
header = header[0:-1)]
if header == “valid”:
a = loadGame.readline()
GameLogic.tst = int(a[0:-1)]

I am using 2.25, in case that makes a difference. :confused:

It looks like you’re not indenting your code. When you have an if <whatever>: the orders that follow the if line have to be indented one tab.

It still doesn’t load. I have no idea what to do.

I think you want something more like this:

loadGame = open("LAK.sav", "r")
header = readline()
header = str(header[0:-1])
if header == "valid":
   a = loadGame.readline()
   GameLogic.tst = int(a[0:-1])

I’m not sure what you’re trying to do with the line “GameLogic.tst = int(a[0:-1])”. The name GameLogic is not defined in this script, and properties, to my knowledge are not stored in the GameLogic module. Also, I prefer to use .strip() rather than [0:-1]. It works like this: whatever=readline().strip()

Why bother with the “string juggle”, save things as they are.

g = GameLogic
cont = g.getCurrentController()

import pickle

if load:
        f = open("pathtofile", "r")
        g.mydata = pickle.load(f)
        g.mydata = [] # List in this case. However any data structure can be pickled.

if save:
    f = open("pathtofile", "w")
    pickle.dump(g.mylist, f)

This code is just a template. It won’t “just work” on it’s own. You have to implement the method for your own needs.
With this example, and the documentation I linked to, you should be more than able to do so.

hmm… looks like something I should learn before my next project.
readline() turned into hell.