ID:168926
 
Code:
//saving objects
proc
ObjectSave()
var/list/objects = new()
var/savefile/F = new("Objects.sav")
for(var/obj/O in world)
if(O.owner)
O.lastx = O.x
O.lasty = O.y
O.lastz = O.z
objects.Add(O)
F["All"] << objects
//loading objects
ObjectLoad()
var/list/objects = new() //creates a new list.
var/savefile/F = new("Objects.sav")
F["All"] >> objects
if(!length(objects))
world<<"<font color=blue>-Announcement-<font color=red><font size=1>ERROR:No objects to load</font>"
return
for(var/obj/B) if(B.loc && B.owner) del(B)
for(var/obj/O in objects)
if(O:Layer == 1)
O.loc = locate(O.lastx,O.lasty,O.lastz)
if(O:Layer == 2)
O.loc = locate(O.lastx,O.lasty,O.lastz)
if(O:Layer == 3)
O.loc = locate(O.lastx,O.lasty,O.lastz)
if(O:Layer == 4)
O.loc = locate(O.lastx,O.lasty,O.lastz)
if(O:Layer == 5)
O.loc = locate(O.lastx,O.lasty,O.lastz)
world<<"<font color=blue>-Announcement-<font color=red><font size=1>All objects hae been loaded by [usr]."


Problem description:When ever i load the objects some times layer 2 objects be under layer 1 objects. How can i fix this problem?

That load proc is just like this one:
proc 
ObjectLoad()
var/list/objects = new()//creates a new list.
var/savefile/F = new("Objects.sav")
F["All"] >> objects
if(!length(objects))
world<<"<font color=blue>-Announcement-<font color=red><font size=1>ERROR:No objects to load</font>"
return
for(var/obj/B) if(B.loc && B.owner) del(B)
for(var/obj/O in objects) if(O:Layer) O.loc = locate(O.lastx,O.lasty,O.lastz)
world<<"<font color=blue>-Announcement-<font color=red><font size=1>All objects hae been loaded by [usr]."

When objects in the savefile cycle through the loop, they cycle through it one at a time, going through every if filter you have, and place themselves if they are layer 1-5. Assuming that those are the only layers you have, what I have up there is exactly the same, just shorter.

To set objects in the way you want to, you'll have to use multiple lists, like the below. I'll use sleep() procs to prevent lag spikes.

proc 
ObjectLoad()
var/list/objects = new()//creates a new list.
var/savefile/F = new("Objects.sav")
F["All"] >> objects
if(!length(objects))
world<<"<font color=blue>-Announcement-<font color=red><font size=1>ERROR:No objects to load</font>"
return
for(var/obj/B) if(B.loc && B.owner) del(B)
for(var/obj/O in objects) if(O:Layer==1) O.loc = locate(O.lastx,O.lasty,O.lastz)
sleep(1)
for(var/obj/O in objects) if(O:Layer==2) O.loc = locate(O.lastx,O.lasty,O.lastz)
sleep(1)
for(var/obj/O in objects) if(O:Layer==3) O.loc = locate(O.lastx,O.lasty,O.lastz)
sleep(1)
for(var/obj/O in objects) if(O:Layer==4) O.loc = locate(O.lastx,O.lasty,O.lastz)
sleep(1)
for(var/obj/O in objects) if(O:Layer==5) O.loc = locate(O.lastx,O.lasty,O.lastz)
world<<"<font color=blue>-Announcement-<font color=red><font size=1>All objects hae been loaded by [usr]."


But, I do not see the reason for deleting all of the objects around unless you use Load Map only at startup. And, in any case, my system works just fine while loading the objects. No extra varialbes of anything. I even customized it for your use, if you want it.
proc/LoadWorld()
var/savefile/F = new ("Objects.sav")
var/obj[0]
F["All"] >> obj
if(length(obj))
for(var/obj/o in mapobj){o.loc=locate(o.saved_x, o.saved_y, o.saved_z);obj.Remove(o)}
obj.Cut()
world<<"<font color=blue>-Announcement-<font color=red><font size=1>All objects hae been loaded by [usr]."
else world<<"<font color=blue>-Announcement-<font color=red><font size=1>ERROR:No objects to load</font>"


But I do believe the problem is that you may set the layer when the object is built. Refrain from doing that unless nesseccary. Other than that, you'll have to use one of the following up there.

In response to CaptFalcon33035 (#1)
THANK YOU VERY MUCH!!
YOU ARE A GENIUS!!