diff gamestate.py @ 183:7b6aba7839ea

getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary. This WILL break old saves.
author Beliar <KarstenBock@gmx.net>
date Thu, 15 Mar 2012 16:24:05 +0100
parents 0d0422243490
children 9e7f494cc850
line wrap: on
line diff
--- a/gamestate.py	Thu Mar 15 14:30:37 2012 +0100
+++ b/gamestate.py	Thu Mar 15 16:24:05 2012 +0100
@@ -35,6 +35,7 @@
             "sqrt":math.sqrt,
             "log":math.log,          
             }
+        self.locals = {}
         
         
     def addObject(self, object_id, map_id, game_object):
@@ -145,12 +146,14 @@
         ret_dict["CurrentMap"] = self.current_map_name
         ret_dict["Quests"] = self.quest_engine.getStateForSaving()
         ret_dict["NPCsMet"] = self.npcs_met
+        ret_dict["locals"] = self.locals
         return ret_dict
 
     def restoreFromState(self, state):
         """Restores the state"""
         self.current_map_name = state["CurrentMap"]
         self.npcs_met = state["NPCsMet"]
+        self.locals = state["locals"]
         self.quest_engine.readQuests()
         self.quest_engine.restoreFromState(state["Quests"])
 
@@ -174,6 +177,8 @@
     def getGameEnvironment(self):
         """Returns a 2 item list containing the entities and functions that 
         can work with it. This can be used in functions like eval or exec"""
-        vals = {}
-        vals.update(self.getObjectDictOfMap(self.current_map_name))
-        return self.funcs, vals
\ No newline at end of file
+        globals = {}
+        globals.update(self.funcs)
+        globals.update(self.getObjectDictOfMap(self.current_map_name))
+        
+        return globals,  self.locals