send info to suspended scene via message?

I have a pause menu which works absolutely perfectly except for the fact that adjustments made on it cannot be transferred to the main scene as of yet, what happens is that the main scene suspends and overlays the pause menu which i can interact with, change integer, and boolean properties on, and then i try to send the altered results as string values to the main scene, but since it is supended it does not recieve them, how else could i send data from one scene to a suspended scene, also another problem i have is when i close and reopen the pause scene, the settings i changed are reverted to their original values.

any help appreciated!


best way to transfer data from and to an overlay (one of them inactive) is to use python’s globalDict.
This can store data, so you can reuse it whenever it is needed.

saving with globaldict

from bge import logic

GD = logic.globalDict
if not 'menu' in GD: 
    GD['menu'] = {}
GD['menu']['button_1'] = 'button_1 statics like properties'

and the loading part

from bge import logic

GD = logic.globalDict  
if not GD:
    print('*** NO SAVEGAME FOUND! ***') 
    print('(Use the save button first)')

button_1        = GD['menu']['button_1']

For a more detailed version you can search the forum/web or check the save load in my signature.

Thanx for this man, just curious is there a way to make all variables global without using dictionaries, eg all variables accessed from all scenes?

In short, not that I know of. I think the global dictionary is the cleanest way, and the actual intended method for having global variables.

However, it is possible to access all variables of all objects, in all scenes via python. So technically speaking, all variables are global to some extent, in the fact that they can all be accessed from anywhere.

Once you know how to get a handle to scenes, objects and objects variables, your’e all good.


#Get a handle to a scene
h_Scene = logic.getSceneList()[0] #Change the index number to choose which scene to get a handle too

#Get a handle to an object in a scene
h_object = h_Scene.objects['NameOfObject'] 

#Get a handle to a variable in the object
h_Variable = h_object['ObjectVariable']

Manipulate variable in another object:

MainGameScene = logic.getSceneList()[0]
MainGameScene.objects['GameController']['Score'] = 10

I often have empties that act as controllers that hold general data about the game.

If you want to save those changes, you WILL need to either use the global dictionary OR create your own save/load system. The global dictionary really isn’t that hard to use though if you are just saving basic variables.

Thanks, thats really useful, i knew how to use bge.logic.getCurrentScene() but i never knew how to access other scenes.

Glad I could help :slight_smile:

BTW, I made edits to my reply a few times after I first posted it, with some more info, so maybe check my previous reply again just in case you didn’t see all of it :slight_smile:

Also, the global dictionary is very very simple to use. I’ll give you a very stripped down example, so you can see just how simple it really is.

##Saving variables to the global dictionary##

#You can create the variables on the fly. They don't need to be declared already
logic.globalDict['myVariable'] = 10

#Then save

That’s it to save variables. Very easy!. Now to load…

#First, load the dictionary

#Now you can access any variables in it
myVariable = logic.globalDict['myVariable']

That is it. Very very simple!.

Remember that the global dictionary actually saves the variables in a file on your computer, so you can access the variables you’ve changed even after closing blender and running your game again. So it’s good for saving settings that you don’t want to change every time you play the game.