script that save and load object rotation

any one have a script that save and load object rotation?

how i can add rotation in this script?:

import bgefrom bge import logic
path = logic.expandPath("//")


cont = logic.getCurrentController()
own = cont.owner 
file = open(path+"reset_position.txt",'r')
info = file.readline()
own.position.x = int(info[0])
own.position.y = int(info[0])

thank you for any help

Attachments

reset_position.zip (72.4 KB)

look for a save and load file in the resource section(or in my sig).

obj.worldOrientation = other_obj.worldOrientation

Hello! I’ve made this script to save and load from a JSON file. Press SPACEBAR to save, and it will load automatically when the game restarts. It saves all the object’s properties in the scene (like position, rotation, states, properties, and so on). I’m sorry the comments in the script are in portuguese, I don’t have time to translate it, but I’m sure you can figure out how the script works. I hope it helps. :wink:

ex_savegame.zip (75.5 KB)

here is a simple example on how to get the Orientation (Rotation) in a format that is easy to store to disk.


obj = scene.objects["Cube"]

tmp = list(obj.worldOrientation)
Orientation = [ list(tmp[0]), list(tmp[1]), list(tmp[2]) ]


and to get position of and object.


obj = scene.objects["Cube"]

Position = list(obj.worldPosition)

and the scale of an object.


obj = scene.objects["Cube"]

Scale = list(obj.worldScale)

the outputs of the snippets above are lists , to store them do disk convert them to a string.