hello all,
Any1 know why this code not work if i restart my scene in game?
when i start it go good but if restart scene it stops working…
import bge
scene = bge.logic.getCurrentScene()
objects = scene.objects
#set global varialbles instances
if not "properties" in bge.logic.globalDict:
bge.logic.globalDict["properties"] ={}
if not "position" in bge.logic.globalDict:
bge.logic.globalDict["position"] ={}
if not "orientation" in bge.logic.globalDict:
bge.logic.globalDict["orientation"] ={}
def save():
controller = bge.logic.getCurrentController()
owner = controller.owner
#sets local properties
for object in objects:
if type(object)==bge.types.KX_GameObject:
bge.logic.globalDict["position"][str(object)] = list(object.worldPosition)
bge.logic.globalDict["orientation"][str(object)] = list(object.worldOrientation[0]),list(object.worldOrientation[1]),list(object.worldOrientation[2])
for property in object.getPropertyNames():
if len(object.getPropertyNames()) > 0:
bge.logic.globalDict["properties"][str(object)] = {}
bge.logic.globalDict["properties"][str(object)][property] = object[property]
#sets position and orientation
bge.logic.saveGlobalDict()
print("Saved File")
endgame = [sens for sens in controller.sensors if type(sens) == bge.types.SCA_KeyboardSensor]
if len(endgame)>0:
if endgame[0].key == bge.events.ESCKEY:
bge.logic.endGame()
def load():
#imports properties from the save actuator
bge.logic.loadGlobalDict()
#sets the properties from the globalDict imports
for ob in bge.logic.globalDict["position"].keys():
if ob in objects:
object = objects[ob]
#sets the orientations from the globalDict imports
object.worldPosition = tuple(bge.logic.globalDict["position"][ob])
object.worldOrientation = tuple(bge.logic.globalDict["orientation"][ob])
if ob in bge.logic.globalDict["properties"]:
for property in bge.logic.globalDict["properties"][ob].keys():
object[property] = bge.logic.globalDict["properties"][ob][property]
print("Loaded File")
how i can resolve?
tanks all