ID:139127
 
Code:
mob
proc
load()
if(fexists("savespot/[usr.key]"))
if(usr.client)
var/savefile/load
load = new ("savespot/[usr.key]")
load["mob"] >> usr
load["x"] >> usr.x
load["y"] >> usr.y
load["z"] >> usr.z


Problem description:

It seems completely random that a mob bugs out and cannot be loaded, runtime errors like this
runtime error: Cannot modify null.x.
proc name: load (/mob/proc/load)
source file: Login.dm,30

And I cannot figure the problem out...

proc name: load (/mob/proc/load)
source file: Login.dm,30
usr: null
src: Pika1516 (/mob)
call stack:
Pika1516 (/mob): load()
the load (16,2,1) (/turf/load): Click(the load (16,2,1) (/turf/load), "mapwindow.map", "icon-x=32;icon-y=12;left=1;scr...")
The mob may randomly not load at all despite the save being in the correct folder.
Don't use usr in procs.
You should use Write and Read procs for saving and loading, but you will have to overwrite them to be able to save the location.
mob/verb/Save()
var/savefile/F= new("savespot/[usr.ckey].sav")//this will make new savefile if there is none with such name, but will "import" it in the game for the use if there is one
usr.Write(F)//calls built-in Write proc, which saves all non-tmp vars
usr<<"Saved!"//outputs the message

mob/verb/Load()
if(fexists("savespot/[usr.ckey].sav"))//You don't want to load someone without savefile
var/savefile/F= new("savespot/[usr.ckey].sav")//and this will only import the savefile for the use, it won't remove it
usr.Read(F)//Calls Read proc, which will update the vars with info in the savefile
usr<<"Loaded!"
else
usr<<"You have no savefile!"


mob
//Write and Read don't automatically save the coordinates, so you will have to overwrie them
Write(F)//A write proc is for saving info into a file
F["x"]<< src.x//on saving, we just add new "path"(which is "x") and set it to our coordinate, then do it with other coordinates
F["y"]<< src.y
F["z"]<< src.z
..()//we also want to save other vars too, but we can easily do it by calling parent proc with ..() and save us some time
Read(F)//A read proc reads the info from the savefile and edits the vars to it
F["x"]>> src.x//this will edit the x var to the one we saved before, do this to the other coordinates too and you willbe moved where you saved
F["y"]>> src.y
F["z"]>> src.z
..()//we need to read other vars too
In response to Martys1103
You should not be calling Read() and Write() directly, it can have ill effects on a savefile. A good example of how to do this properly can be found at [link].