globalDict not saving??

I’m new to using globalDict, and i understand it quite well, but im uncertain of how to save the globalDict, i tried using logic actuator, but im not sure if it is working. Basically what i am trying to do is save data in globalDict and be able to access it all the time, i save the worldPosition of an object, then when i press a key it is meant to set the worldPosition of that object back to what the save is (since it is on another scene and resets itself when the scene is removed and added), but i get an error that says: “RunTime Error: Vector read, user has become invalid”, in the console.

any help appreciated.

I think you better store a copy of the position (vector):


valueToSave = object.worldPosition.copy()

As worldPosition and Co. return a reference (which gets updated all the time) it makes no sense to store it anyway. On access you would get the value from current frame not from the past.

Some values of objects needs to be converted into vector or lists.

Like worldposition needs to be converted, this case a list would do it:

obj_data['position']    = list(obj.worldPosition)

Also linear and angular velocities needs to be in list format, they also need a getPhysicsId check.

Orientation needs to be list type with vector, and you need to loop trough it:


[list(vector) for vector in obj.worldOrientation]

And saving properties is a bit harder to get them all, same method as above loop trough and give a key with it:

obj_data['properties']  = {prop: obj[prop] for prop in obj.getPropertyNames()}

Loading properties is a bit tough aswell:

        properties = obj['properties'] #the loaded properties (not the object one)

        for prop_name, prop_value in properties.items():
           loaded_obj[prop_name] = prop_value

SAVE GD with python:

bge.logic.saveGlobalDict()

LOAD GD with python:

bge.logic.loadGlobalDict()

As monster said, it is propably better to copy the location/orientation, etc.