Game Logic: globalDict

globalDict
  • gets/sets variables to a global dictionary.
  • This is the Blender Game Engine version of a python dictionary. 
Note:
  • A dictionary is a python data structure.  Different types (float, integer, string, dictionary, etc) of data can be stored in the same dictionary.
     
  • saveGlobalDict() saves globalDict to a file on your hard drive.
     
  • loadGlobalDict() loads globalDict from a file on your hard drive
Sample Code

################## Add data to the Blender globalDict
   

# import bge
import bge

#create a regular dictionary for player 1 stats
player1_Stats = {  "Health" : 80, "Armor" : 30, "Class" : "Cleric"  }                

#create a regular dictionary for player 2 stats
player2_Stats = {  "Health" : 60, "Armor" : 90, "Class" : "Warrior"  }

# add player 1 to the Blender globalDict
bge.logic.globalDict["player1"] = player1_Stats

# add player2 to the Blender globalDict
bge.logic.globalDict["player2"] = player2_Stats

Sample Code

################## Get data from the Blender globalDict
  

# import bge
import bge

# get player 1 stats that were added to the Blender globalDict
player1_stats = bge.logic.globalDict["player1"]

# get player 2 stats that were added to the Blender globalDict
player2_stats = bge.logic.globalDict["player2"]