ID:157747
 
Hello,

In my current game I'm working on I'm using a simple stat pannel inventory system that just uses src.contents, and I have it all equpping and everything the way I wanted with overlays. The thing I don't know how to do is save everything in the inventory (or src.contents) when the user logs out so everything will still be there when the user logs in again.

Anyone know how I might be able to do this?

Thanks in advance!
Any and all non temporary variables will be saved automatically when atom.Write() is called, including contents.
In response to Spunky_Girl
Spunky_Girl wrote:
Any and all non temporary variables will be saved automatically when atom.Write() is called, including contents.

The code I'm using to save currently is:

mob
proc
Save() //Save procedure
var/savefile/S = new("Saves/[src.ckey]") //Creates a new save of your last saved character
S["last_x"] << src.x //stores last X coordinate
S["last_y"] << src.y //stores last Y coordinate
S["last_z"] << src.z //stores last Z coordinate
S["Name"] << rpname
S["Inven"] << src.contents
Write(S) // Writes the stored files into one
SaveObjects()
Load() //Load procedure
if(fexists("Saves/[src.ckey]")) // Looks for written save file and if it exists it allows acces to load
var/savefile/S = new("Saves/[src.ckey]") //opens the old save file
Read(S) //Reads it
S["last_x"] >> src.x //Loads the last X Coordinate
S["last_y"] >> src.y //Loads the last Y Coordinate
S["last_z"] >> src.z //Loads the last Z Coordinate
S["Name"] >> rpname
S["Inven"] >> src.contents
LoadObjects()
else


How and where would I put the atom.Write() you mentioned and how would I tell it to read it again?
In response to Jewntansoath
You already have it but you should not be calling Write() directly. The proper way to save/load is like so:

client
New()
if(fexists("[key].save"))
var/savefile/F = new("[key].save")
F >> mob
..()
Del()
var/savefile/F = new("[key].save")
F << mob
..()

mob
//any special processing goes in Write() and Read(), for example saving x,y,z
Write(var/savefile/F)
..()
F["x"] << x
F["y"] << y
F["z"] << z
Read(var/savefile/F)
..()
loc = locate(F["x"], F["y"], F["z"])


Note that any variables not declared tmp will be saved automatically and so you don't need to fiddle with them (like contents and presumably your rpname variable).
In response to Garthor
Hey, thanks, Garthor. I just merely replaced my old code with what you wrote and it worked. If I change just a few things in what I have set up it should all be fine!
In response to Jewntansoath
What ive seen is that people create a skill name variable, and if it is set to 0, they dont have the skill, and if it is set to 1, they do have it.
Sorry for restarting an old discussion, but I tried Garthor's code he posted and it did work fine in doing everything I wanted, but as I was testing my game again I noticed that the overlays I have for armor and such on the mob are saving, but they won't come off again! I've tried MANY different things in trying to get it to work but I still can't get it. Is there something I could add or change to let me be able to still add and remove those overlays after they save?
In response to Jewntansoath
This is because when you save an atom with overlays, they become merged with the icon. To get around this, you have to move the atom's overlays to a separate list then save the list (make sure the atom's overlays is also empty). After the atom loads, you can set the atom's overlays to the saved list.
In response to Mega fart cannon
They don't become merged with the icon, it's just that it's rather difficult to remove them from overlays across sessions, because the requirements for something being the "same" with respect to the overlays list is rather obnoxiously specific.

The best thing to do is just not save the overlays at all and reconstruct them from pertinent data afterwards. For example:

obj/item/equipment
proc/Update_Overlay(var/mob/M)
M.overlays += src

mob
Write(var/savefile/F)
..()
//don't save overlays
F.dir.Remove("overlays")
Read(var/savefile/F)
..()
//reconstruct overlays from equipment
for(var/obj/item/equipment/E in equipped)
E.Update_Overlay(src)
In response to Garthor
Ah, I see. I always thought they just merged with the icon since that's what it seemed like.
In response to Garthor
I don't understand what the "in equipped" means in:

for(var/obj/item/equipment/E in equipped)
E.Update_Overlay(src)


Is it a variable that needs to be defined? And if it is, what do I define it with (i.e. var/equipped = "what goes here")?
In response to Jewntansoath
In his example, equipped (really src.equipped) is supposed to be a variable of the mob that contains a list of its equipped items.
You should read up on the DM Reference about lists and for()-list.