Setting Setter Tutorial


We can store settings and keybinds in a module for easy access.


Json Coder
Extended Expand Path


Place this code in a file called, located in the same directory as the blend.

import jsonCoder as json
from expandPath import expandPath
class SettingSetter():
  def __init__(self, iniPath='//system/settings.ini'):
    iniPath = expandPath(iniPath, check=True)
    import configparser
    sheet = configparser.ConfigParser()
    # This make entrys case sensitive.
    sheet.optionxform = str
    # Read the .ini file into the the ConfigParser object
    # Get every subsection in the sheet.
    for section in sheet.sections():
      for subsection in sheet[section]:
        msg = sheet[section][subsection]
        # We do some error checking so that we have better knowledge of what any problems are.
        try:  msg = json.loads(msg)
        except KeyError:
          err = iniPath+' :  unrecognized entry in ['+section+']['+subsection+']; '+msg
          raise KeyError(err)
        except FileNotFoundError:
          err = iniPath+' :  missing file in ['+section+']['+subsection+']; '+msg
          raise FileNotFoundError(err)
        # Every subsection needs to be unique, sense we store them as an attribute on the SettingSetter
        if hasattr(self, subsection):
          err = iniPath+':  duplicate entry in['+section+']['+subsection+']; all Subsection must be unique irrespective of Section.'
          raise KeyError(err)
        # Set the entry as an attribute for easy access.
          setattr(self, subsection, msg)
# Override this module with our custom object.
import sys
sys.modules[__name__] = SettingSetter()

Example .ini

Place this code in a file called setting.ini, located in //system/.

camScroll = 0.1
camZoom = 0.1

forward = {"Key": "EKEY"}
backward = {"Key": "DKEY"}
leftward = {"Key": "SKEY"}
rightward = {"Key": "FKEY"}
spaceward = {"Key": "SPACEKEY"}


Make shure you have the following files.

import settingSetter as keys
import bge
own = bge.logic.getCurrentController.owner
if keys.forward.held:
  own.worldPosition.y += keys.camScroll


Log in and edit this page to ask and answer questions.

Further Reading

Make a Subscriptable Module
Bge Keybind Codes
Bge Input Events

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License