Results 1 to 2 of 2

Thread: Load And Saving

  1. #1

    Load And Saving

    I'm trying to create a save system in my game i want to use global Dictionary but i cant find away to save the health property or any other property can some one help me

  2. #2
    Moderator Monster's Avatar
    Join Date
    Jan 2006
    I guess you are talking about the BGE.

    You need to place the "data to be saved" in the global dict via a custom Python controller. Be aware you need to use a marshallable data type such as string, int, float, boolean, list, dict. The content of the containers are restricted the same way.


    import bge
    storage = bge.logic.globalDict
    def storeHealth():
       owner = getOwner()
       healthValue = owner["health"]
       storage["player's health"] = healthValue
    def restoreHealth()
        healthValue = storage["player's health"]
        owner = getOwner()
        owner["health"] = storage["player's health"]
    def getOwner():
         return bge.logic.getCurrentController().owner
    The final implementation depends on what storage structure you want to use.
    E.g. Top level = save point, 2nd level = object name, 3rd level = object elements
        "savepoint 1": {
            "player" : {
                "position": [0.0, 0.0, 0.0],
                "properties": {
                    "health": 98.3,
                    "armory": 7.5
            "merchant alpha": {
                "position": [130.2, 78.3, 2.8],
                "properties": {
                    "gold": 133
    As you see this can become quite complex. So you should think about before hand.
    Last edited by Monster; 04-Sep-17 at 00:02.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts