save/load script for a game??

Hello,
I’m trying to make a game with a save/load function. Does anyone know how to do this? I already found a script which saves the position/orientation of a single cube:

 
Save Script:
 
### Add objects to be saved to this list ###
cube = GameLogic.getCurrentScene().getObjectLis t()["OBCube"]
cubePosi = cube.getPosition()
cubeRot = cube.getOrientation()
 
### Open the file "Game1.sav" in write mode
saveFile = open("Game1.sav", "w")
### Write header to file
saveFile.write("This is a valid save file
")
 
### Write game data to file
for x in range(len(cubePosi)):
saveFile.write(str(cubePosi[x]) + "
")
for x in range(len(cubeRot)):
for y in range(len(cubeRot[x])):
saveFile.write(str(cubeRot[x][y]) + "
")
 
### Close save file
saveFile.close()
 
 
 
Load Script:
 
### Add objects to be saved to this list ###
cube = GameLogic.getCurrentScene().getObjectLis t()["OBCube"]
cubePosi = cube.getPosition()
cubeRot = cube.getOrientation()
 
### Open the file "Game1.sav" in read mode
loadFile = open("Game1.sav", "r")
### Check for the header
header = loadFile.readline()
header = header[0:-1]
 
if header == "This is a valid save file":
### Load game data from file
for x in range(len(cubePosi)):
loadCoord = loadFile.readline()
cubePosi[x] = float(loadCoord[0:-1])
cube.setPosition(cubePosi)
for x in range(len(cubeRot)):
for y in range(len(cubeRot[x])):
loadCoord = loadFile.readline()
cubeRot[x][y] = float(loadCoord[0:-1])
cube.setOrientation(cubeRot)
 
### Close save file
loadFile.close()

Can somebody tell me how to change this script so that you can save/load every object?

i got another one that works somewere.
ill get it

To save the game you can use the Save/Load logic brick.