Link logic across scenes?

So i was wondering if it was possible to link data across 2 or more scene.
For example if a player is in a small town, and each houses door goes to a separate scene (inside of the house)
can you transfer the players data (ammo, health, etc). Also when he leaves a building, to spawn him again wit the same data, infront of the building he went into.

You have to store all properties into the global dictionary. You can store integers, floats, lists, dictionaries, … and restore the objects in every new scene, as long as the game is running. Like this, for example:

from bge import logic

def store(cont):
    player = cont.owner
    player_properties = {name: player[name] for name in player.getPropertyNames()}
    logic.globalDict['player_properties'] = player_properties
def restore(cont):
    player = cont.owner
    player_properties = logic.globalDict['player_properties']
    for key, value in player_properties:
        player[key] = value

If you want to be able to save and load your game, store the contents of the global dictionary into a text file with the pickle module. For use with the pickle module, search the resources section.

Please look for saveload.

This topic comes up regularly. I’m sure you will find relevant threads.