A little guidance please.

I’ve been working on my game save, nothing elaborate…just writing properties(and player orientation) to a file. I want to however create a separate file with a list of game objects in the scene and compare it to the current scene…if there is an object that is not on the list I want to delete it…

Is this an ok way to go about it, or is there an easier way…my way is not so complicated…but since this is the first time I’ve done this I wanted some insight.

why not do it the other way around ?
delete all movable objects and add in the objects from the list !

because it would not take into account all the objects properties to and it just turns into a lot of extra work, it would also be slower …and I am lazy…I also try to keep it as simplistic as possible…I am not the best coder…

So far I have it writing the objects to the file I am just fighting a little with reading the list, info in this case…and deleting the objects…

I’m sure I will need to work out some other issues as well. If something is out of range etc.

I do it simply by writing the objects per line, straightforward stuff:


for x in range(len(obj)):
    file.write(str(obj[x])+"\r")

then reading that back:


file = open(path + 'save.txt','r')
    info = file.readlines()

    for x in range(len(obj)):
        if str(obj[x])+'
' not in info:#writing to the file appends the newline escape sequence so I add it here or the strings do not match
            str(obj[x]).endObject()
            

I am having trouble with it though...simply cannot figure out what my mistakes are though...

I have also tried:

x.endObject()

but ‘x’ is just an index as far as I can tell and does not return a string.

i put a blend together that does what you are describing, delete objects thats not in the list.

http://15b.dk/blendfiles/level-store.blend

sweet!, thanks…I will look at it later, I have diverted my energy for the moment :)…can I PM you if I have any issues?

actually, I really appreciate the help, but I looked at your(much cleaner code than mine :))code and it was nearly over my head…for you it is basic python :)…it’s ok…I managed to get mine working by changing how I handled the obj index and naming convention…converting it to a string like that was a mistake. instead I tested for ‘obj[x].name’ and if it was not in the list I did obj[x].endObject() simple as that…I just needed a break, so I could get fresh eyes on the code.

I also had to fiddle with the range since the first 30 variables are not really related...I probably need to break this down to multiple files to keep settings, objects and actors separate.

the most important code is the 3 last lines, the rest is just to get all objects from the scene minus the cubes and store them in a dict , then save the dict to disk and load it right away, (last 3 lines -->) and loop over all objects in the scene, if a object is not in the dict loaded from disk then end the object.
The End.

and also a quick little example of omitting objects :)…I did understand it, but it took me a good 10 minutes to go through it, as it is somewhat cyclic…I had to go back and forth from the two last calls back up to the functions and see what was happening…but I did understand it…just not at first glance :slight_smile: