ID:139606
 
Code:
proc
Save(mob/player/M)

var/savefile/F=new(DetermineSave(M,M.slot))
M.overlays=null

M:Write(F)
M.Overlay_Refresh()
M<<"<center><font color=red>\[Game Saved.\]</font></center>"

Load(mob/player/M)
if(fexists(DetermineSave(M,M.slot)))
var/savefile/F=new(DetermineSave(M,M.slot))

M:Read(F)
mob
Write()
..()
var/savefile/F=new(DetermineSave(src,src.slot))
src.level.Write(F)
Read()
..()
var/savefile/F=new(DetermineSave(src,src.slot))
src.level.Read(F)


I am having issues. I have a 3-slot save system. It displays the name of the character in a grid, with Load/Delete buttons beside it. Everything works just fine until I log in(Which triggers Save()). It freezes up. It does this for any of my datums. When I don't manually save them like this, though, it gives many errors when loading. Can someone explain to me the proper way to go about saving datums?
You are basically killing your savefile with a clever combination of direct calls to Write() (DON'T DO THIS) and just... ugh.

What you should have is:

client/proc
Save()
var/savefile/F = new("[ckey].sav")
F["mob"] << mob
Load()
if(fexists("[ckey].sav"))
var/savefile/F = new("[ckey].sav")
F["mob"] << mob

mob
Write(var/savefile/F)
..()
// Anything special here, such as:
F.dir.Remove(overlays)
Read(var/savefile/F)
..()
// Anything special here


To have multiple "slots", just read/write from somewhere besides "mob". Like, say, "mob1" or "mob2" or "mob3".

I have absolutely no idea what you are trying to do with the level thing.
In response to Garthor
The level is a datum. The player's level variable is a subject of the levels datum. Whenever I try to save any of my datums, such as level, stats, and others, the game stops responding.
In response to Albro1
Albro1 wrote:
The level is a datum. The player's level variable is a subject of the levels datum. Whenever I try to save any of my datums, such as level, stats, and others, the game stops responding.

Garthor's solution is correct, although the root cause of the freeze isn't the direct calls to Write(). They are a bad idea for other reasons, however.

The issue that's causing the freeze is your attempts to re-open the savefile in Read() and Write(). Both of those procs take the savefile as an argument, and a specific savefile can only be open in one /savefile at once. By default any attempts, either by the same game or another game, to open a savefile that is already open will cause the new statement to wait until the currently open version is deleted, which will never happen in your code as it is waiting for the Write()/Read() procs to end before closing the savefile. You can override that by setting the timeout for the open.