ID:142120
 
Code:
mob/proc/saveAllOverlays()
for(var/image/I in usr.overlays) // find every image in the overlays
usr.savedOverlays += I // save every image to a new list
usr.overlays = null // nullify the old list
for(var/image/I in usr.takeOffOverlays) // find every image that can be taken off
usr.TakeOffOverlays += I // save the images to a new list
usr.takeOffOverlays = null // nullify the old list
mob/proc/loadAllSaved()
for(var/image/I in savedOverlays) // find the saved images
usr.overlays += I // add the images back to the users overlays
usr.savedOverlays = null // nullify the saved images list
for(var/image/I in usr.TakeOffOverlays) // find the saved takeoff images
usr.takeOffOverlays += I // add the images back to the takeoff list
usr.TakeOffOverlays = null // nullify the saved takeoff images
mob
proc
Save() //this works but gotta figure out how to save location too
if(usr.x==9&&usr.y==42&&usr.z==1)
return // no saving at title_screen
F = new("/players/[usr.ckey].sav")//"/players/[usr.ckey].sav")
usr.saveAllOverlays() // call the saving all images procedure
usr.last_x = usr.x
usr.last_y = usr.y
usr.last_z = usr.z
F["mob"] << usr
F["last_x"] << usr.last_x
F["last_y"] << usr.last_y
F["last_z"] << usr.last_z
usr << "You're progress has been saved.[F]"
Load()
if(fexists("/players/[usr.ckey].sav"))
F = new("/players/[usr.ckey].sav")
F["mob"] >> usr
F["last_x"] >> usr.last_x
F["last_y"] >> usr.last_y
F["last_z"] >> usr.last_z
usr.loc = locate(usr.last_x, usr.last_y, usr.last_z) // locate the user where they last were
usr << "Welcome back [usr.handle]."
usr.loadAllSaved() // load all the images back
else
usr << "There are currently no saved files with your information."
return
verb/save()
usr.Save()


Problem description:The usr.saveAllOverlays() procedure doesn't even work ... like nothing happens ...? It has to work so all the images can be saved so that when you log out they're still there, and when you log in they return back to their original lists to be manipulated again (like being able to remove them and put them back on)

No put usr in proc. Ungh.

Lummox JR
In response to Lummox JR
Why use src instead of usr? I never understood this because usr seemed so direct whereas src is searching for it's target?
DragonMasterGod wrote:
Problem description:The usr.saveAllOverlays() procedure doesn't even work ... like nothing happens ...?

Because you cannot really loop through the overlays list. Look it up before using it; there are no /images inside. The data inside is in a special internal format, and isn't meant to be accessed directly. Besides, saving overlays (like other icons) in a savefile would just make it needlessly bulky; also, you cannot remove the overlays individually after reloading the object. The best way to accomplish this is keep track of the overlays created, so they can be rebuilt later, which also prevents savefile clutter. Of course, note you can always clear the overlays by using Cut() or just setting it to null.
In response to Kaioken
So in other words, there's no way of looping through the usr.overlays?

Is that why people make a new list like this:
mob/var/list/Overlays = list() // new list

And then assign every image as an overlay to that list, then make a procedure like this:

mob/proc/updateOverlays()
for(var/image/I in usr.Overlays)
usr.overlays += I

And they go about referring to the list using Overlays instead of overlays? Like they'd be able to loop through the Overlays list where as they can't do that with the regular overlays...?
In response to DragonMasterGod
DragonMasterGod wrote:
Why use src instead of usr? I never understood this because usr seemed so direct whereas src is searching for it's target?

No. Both are variables to objects, how are they going to be searching for anything themselves? They're just variables containing some value. But 'usr' is unsuitable, unsafe and a bad practice in procs and 'src' or other vars are fine.
Your understanding seems quite flawed, you should get reading:
http://www.byond.com/docs/ref/info.html#/proc/var/src
http://www.byond.com/docs/ref/info.html#/proc/var/usr
http://www.byond.com/members/ DreamMakers?command=view_post&post=35932
http://www.byond.com/docs/guide/

So in other words, there's no way of looping through the usr.overlays?

Technically, you can do it, but you cannot do much by it, and it is unrecommended.
Is that why people make a new list like this:

Yes. That allows you to freely rebuild the overlays whenever wanted, so you can also cause them to ultimately be saved or change their contents on the fly (by removing the current overlays and rebuilding the list with the changed icons).