Creating a save file


Im wondering how i could create a save file when someone selects “save” when in game, python maybe?

i know about the save/load script but i mean a file that would hold your points, health, items, cords etc… or whatever and you could load from inside the .exe or .blend by going to load (obviously) is this possible?

Im pretty sure it is, i did a little pawno coding for a GTA SA script (online server) and you could have it create a file, it would save your login details, position etc… i wont go into detail about that though…

Well im hoping someone more experienced with python could answer this, thanks


Blendenzo did a very good tutorial on that subject:

You need to know a bit of python of course.


Rhetorical question: is it possible to create an output stream from a blender object (such as a player) with all its associated parameters and such that could be written to a file?

Not sure. Anyone know?

Brilliant, thanks! social but im not so good with python, so i have no clue how to use it :confused:

I tried to create a simple save/load script to let you know how it could be done. In this blend I save the cube position to a file in string format and also load it from the file using the split() function, but sure there are better ways to do it, but well it shows clearly how it works.

How to use?
When you run the game, use the arrows: “up”, “down”, “left”, “right”, to move the cube, and “S” to save the position. When you exit the game and start again, press “L” and the cube will be positioned were you saved it. Also notice when you play around with creating files with python in blender, when you double click a blend file, the file created using python is in the same directory as the blend file. When you load up blender and load a blender file with the File > Open, function and then run a python script to create a file, the file will not be placed in the same dir as the blend but in the Blender.exe dir. So remember that when you have problems finding the save file. :slight_smile:

Right now it saves only 1 object position, but actually with some minor changes it can save a bunch of positions, you just need to find a good way to save it, maybe pickle, database, or a good organised string.

Maybe for devs checking this forum, try removing eval(), to not convert string to a float, it’s pretty cool, because afther loading the save file and exit the game Blender instandly crashes.

Oeps, sorry something went wrong, no idea how to remove your own post :S

Strange time for Blender Game Engine…
Erwin and Snailrose are working a COLLADA exporter and importer and if I am not wrong inside the game engine. ( It must be useful for the echo project ). With the COLLADA import and export the most of the work for a perfect save is done.
Also if you store the Matrix of the objects you have position and rotation. then if you store and the bullet physics things of the time you have stored and the physics.
After that the how to create a save it’s up to the type of a game. For example for an arcanoid stily game the above are enought , for an adventure game you will have to store inventory items and lots of other scene properties.
Genaraly speaking if you organise you game or with other words if you had made your disigne of your game the things that you will have to save will be clear.
One good way that stay in my mind is that I will have a string property for every object. This string will be the type of the object this way you can separate the special properties that you have to store for special objects.

Over all start learning PYTHON there is a reason that even universities abandoned Basic and now use Python for the curses of the beginers. Also Python it’s very organised and open source. This means that you will find documents free of charge and complete books that you can download and read , also if you buy one of those books automatic you give some donation to python.
BGE it’s a very good tool to learn Python as you get visual results… but be carefull. The missunderstanding of 3D maths may confuse you.
Looks like I was in the mood to write again.

Perhaps it would be easier if you give your game restore points to re-spawn from when you die or restart?? Then you would only have to save say, your inventory and some information about the state-of-play, but not have to worry about your character’s exact position and movement at the time.