ID:264921
 
Code:
mob
proc
Save()
fdel("savefile/[copytext(usr.ckey,1,2)]/[usr.ckey].trpgs")
var/savefile/F=new("savefile/[copytext(usr.ckey,1,2)]/[src.ckey].trpgs")
src.Write(F) // writes your variables/lists onto it
Load()

if(fexists("savefile/[copytext(usr.ckey,1,2)]/[usr.ckey].trpgs"))
var/savefile/F=new("savefile/[copytext(usr.ckey,1,2)]/[src.ckey].trpgs")
src.Read(F)
src.checkpoint()
else
usr << "No Save File"
return


Problem description:
This has happened on several different projects; and I'm certain it has absolutely nothing to do with the code, but with the content of the savefile. My problem is, when I have
with certain things in it (of what I'm not sure) saving goes really crappily; what I -think- is happening is that the login procedure is failing, so it is restarting (not sure why).

For instance: Randomly, when I log in, saving/loading works, but sometimes I log in, and I hit load, and it repeatedly asks me to load, bringing up some sort of runtime error each time I press load (the error is not the problem; it has been different everytime I have encountered this problem, it's usually something to do with bad client, or a variable being null due to a failure of loading vars). And it doesn't kick me out, and make me start over, I just stay, and Login() keeps repeating; it even places me back to my saved location, but continues to get very buggy, and spams my screen with runtimes.

Are there certain things you cannot have in a savefile, or else it will fail when reading? If so, what? Because I have encountered this in many projects.
It's bad idea to save other mobs into savefile, if you saved two mobs it might cause that
Your first mistake is calling Write() and Read() directly. Doing so is generally unsafe and often results in mangled savefiles. Instead, you should be using the << and >> operators to save and load mobs. So, for example:

// To save:
F["mob"] << mob

// To load:
var/mob/M
F["mob"] >> M


M here is essentially meaningless, the savefile just needs a variable to read the mob out into.

Note that, by doing so, a NEW mob is created when you load a savefile: you can't load directly into a mob that already exists. Of course, seeing as the mob in the savefile isn't even necessarily the same type, this is not altogether unreasonable.

Another common issue is that you are saving a reference to another player in your savefile. If you have a variable pointing to another player, that player will get saved along with your character in the savefile, causing all sorts of issues. For instance:

mob
var/friend
verb/make_friend(var/mob/M)
src.friend = M


The friend variable now is a reference to another mob, and that mob will be saved in your savefile, which causes it to get loaded along with your mob, and all sorts of seemingly-random issues. The simplest fix is just to declare any such variables as tmp, such as var/tmp/friend.


Anyway, to get an actual sense as to what, exactly, is causing the problem, we need to see the savefile itself, which can be accomplished by using the ExportText() procedure.