HELP! : Save game...

Hello! I wanna make a game in which there will be 5 levels, If you pass the first, the second will be unlocked etc.

So the problem is :

If for example I play and unlock the 4th level and then close my game, then when I reopen it I want to have it unlocked and not having to pass all the levels again…

In other words, I want a way to save my process in the game…

Please HELP!! :spin::eek:

Write the information you want to store in GameLogic.globalDict (obvious by Python code).
Then use the save actuator to write it to a file.

Read from file with the load actuator.
Take the information from GameLogic.globalDict (obvious by Python code).

Optional:
You can save and read files with Python too.

Thanx for your answer! I understood the way to do that, but I unfortunately don’t know python… :frowning:

Could you give some more explanation of that?

#1 save

from bge import logic as gl
gl.globalDict[“blah”]=info
gl.saveGlobalDict()

#2 load

from bge import logic as gl
gl.loadGlobalDict()
info=gl.globalDict[“blah”]

Oh thank you so much…!!

Anyway, the “Blah” will be a property or a file or …?

no. a unique id to store data in globaldict. info can be a string, no etc.

If you were wanting to save object properties for example, connect an always sensor (True Pulse) to a script controller
Then, (if you wanted to be really complex) you could make a script that saves Every property to a single GlobalDict Variable.
This particular example would only work if it were used on one object, (you could use on more than one if you changed the name of the GlobalDict variable.)


import bge
controller = bge.logic.getCurrentController()
owner = controller.owner
if not "properties" in bge.logic.globalDict:
	bge.logic.globalDict["properties"] ={}

def save():
	for property in owner.getPropertyNames():
		bge.logic.globalDict["properties"][property] = owner[property]    
	controller.activate(controller.actuators["save"])
	print(bge.logic.globalDict["properties"])

def load():
	controller.activate(controller.actuators["save"])
	for property in bge.logic.globalDict["properties"].keys():
		owner[property] = bge.logic.globalDict["properties"][property]   
	print(bge.logic.globalDict["properties"])   
if controller.sensors["s"].positive:
    save()
elif controller.sensors["l"].positive:
    load()
                         

This script will save and load all the object properties.
attach two actuators( a game: save and a game: load), called “save” and “load”.
Make two sensors, called s and l, s = save, l = load
Then when you activate sensor l it will load the properties, but if you activate sensor s it saves properties

Thanx! Btw, I found the Blendenzo’s tutorial which sais how to save staff by creating a new file…

yes, that’s another way, only useful for using multiple game saves

for simpler games you can use password
at the level end you give the password and from the menu the player can start the levels using the passwords

Oh yeah!! The idea with the password is awesome and many mini games use it… thnx!