Hi everyone I am trying to make a script used to save / load all the properties of all the scenes in my blender game. I followed a tutorial here but still it uses blender 2.4x and scipt does not work on Blender 2.6. I copied the script entirely, but nothing to do … Is someone can help me please?
Herebellow the scripts :
Save script
import GameLogic
save = GameLogic.getCurrentController().sensors["save"]
if save.positive:
saveFile=open("Game1.sav","w")
ObjList = GameLogic.getCurrentScene().objects
for x in range(len(ObjList)):
if obj.has_key('notsaved')==False:
saveList=[]
saveList.append(obj.position)
for y in range(3):
saveList.append(obj.orientation[y])
for y in range(len(obj.getPropertyNames())):
prop=obj.getPropertyNames()[y]
value=obj[prop]
propList=[]
propList.append(prop)
propList.append(value)
saveList.append(propList)
saveFile.wirite(str(obj))
for y in range(len(saveList)):
saveFile.write(str(saveList[y]))
saveFile.write("
")
saveFile.close()
Load script
import GameLogic as G
load = G.getCurrentController().sensors["load"]
if load.positive:
#Read SaveFile
fileHandle=open('Game1.sav',"r")
lines=fileHandle.readlines()
fileHandle.close()
for i in xrange(len(lines)):
objfound=False
step=0 #Reading steps => Position, orient1,2,3, props
tempList=[]
for l in xrange(len(lines[i])):
if objfound == False:
if lines[i][l] == "[":
obj= G.getCurrentScene().objects[lines[i][:l]]
objfound=True
lastl=1
else:
if lines[i][l] == ",":
#Position
if step == 0:
if len(tempList) == 0:
tempList.append(float(lines[i][lastl=1:l]))
lastl=l
elif len(tempList) == 1:
tempList.append(float(lines[i][lastl=2:l]))
lastl=l
#Orientation
elif step > 0 and step < 4 :
if len(tempList) < 2 :
tempList.append(float(lines[i][lastl=2:l]))
lastl=l
#properties
elif step == 4:
propname = lines[i][lastl+3:l-1]
lastl=l
elif lines[i][l] == "]":
#Position
if step == 0:
tempList.append(float(lines[i][lastl+2:l]))
obj.position=tempList
step+=1
tempList=[]
lastl=l
#orientation
elif step > 0 and step < 4 :
tempList.append(float(lines[i][lastl+2:l]))
if step=2:
orient1=tempList
elif step == 2:
orient2=tempList
else:
obj.orientation=[orient1,orient2,tempList]
step+=1
tempList=[]
lastl=l
#Properties
elif step ==4:
if lines[i][l-1]=="'":
propvalue=lines[i][lastl+3:l-1]
else :
propvalue=float(lines[i][lastl+1:l])
lastl=l
obj[propname]=propvalue
print propname)
print obj[propname]