saving files in a game

Whats the best way to save files during a game?

Are their any pre-written scripts.

sorry, i couldn’t find an answeer when search in just a lot of refrences to python to saveing

What are you trying to save? You can really only save with python and you use python methods for writing files. If your wanting to do something like that, your best off learning python. It’s one of the easiest languages to learn. There are tutorials all over the net. It will help you write better games and really get you by for any kind of programming, and it’s fun.

i am wanting to save some basic details of game at a save game location- possion, items etc.

I was wanting to see what other have done with python in blender. trying to improve my ideas as much as possible, by learning from others … definatly not mySLQ, not what i have i mind for now.

That’s how you create a new text file within Blender. I don’t know if that works in the game engine and don’t have the time to check it out right now.

I would love to hear if this worked for you or not…

Crud. I just assumed I could write files from the game engine, but I just tried it and I couldn’t.

No. I just didn’t import sys and append the path. There’s a great example here under saving scripts:
http://www.fortunecity.com/skyscraper/true/947/id14.htm

Do calls like “open” work from within Blender?


import GameLogic

con = GameLogic.getCurrentController()
own = con.getOwner()
pos1 = own.getPosition()

#####- Save -#####

pos2 = repr(pos1)
fs = open("GameSave.pwn", "w")
fs.write(pos2)
fs.close

#####- Load -#####

fl = open("GameSave.pwn", "r")
pos3 = fs.read()
fs.close
pos4 = eval(pos3)

#####- Set -#####

own.setPosition(pos4)

By the way, you will not be able to just copy and paste in that script, you need to modify it to make it save/load with a sensor or something. Good luck!

I might have made a mistake, i don’t think i did though.

thanks guys :slight_smile:

I was really hopping for a few more scripts, so i can get my scripts as eficiant as possible but thanks for the help…feel free to add any other links to saves scripts, i would really appreaciate it.