ID:1391662
 
(See the best response by Nadrew.)
Code:
mob
Logout()
var/filename = "Players/[ckey].sav"
var/savefile/F = new(filename)
F["S_x"] << x
F["S_y"] << y
F["S_z"] << z
Write(F)



mob
Write(savefile/F)
..()
F["S_x"]<<x
F["S_y"]<<y
F["S_z"]<<z

Read(savefile/F)
..()
var{S_x;S_y;S_z}
F["S_x"]>>S_x
F["S_y"]>>S_y
F["S_z"]>>S_z
loc=locate(S_x,S_y,S_z)


Problem description:Above shows my auto save so players don't ever have to worry about loosing progress if they ever to crash, reboot or the game goes down. I'm trying to figure out on how to code in the loading part, so players can load their previous play.

Best response
It can be as simple as checking if the file exists and asking if they want to load it, or you can get a bit more complicated and go the route of a graphical loading screen. Either way you need to start off by first correcting your saving code, instead of manually calling Write() you should be using << to spit the entire mob into the file (which in turn calls Write() the proper way), next you're gonna want to contain your saving and loading code in their own procs so you can call them easily whenever you need them.

mob
proc
Save()
var/savefile/F = new("Players/[ckey].sav")
F["player"] << src
Load()
var/file_name = "Players/[ckey].sav"
if(fexists(file_name))
var/savefile/F = new(file_name)
if(F["player"]) F["player"] >> src


Now, since you're already using Write() and Read() to save and load the location stuff you don't need to worry about that.

You'll however, want to split your player mob into its own subtype, since loading will call mob/Login() again and you don't want it being possible to get stuck in a loading loop. This also means you'll want to make your initial mob (the one connected to before loading) its own type.

mob
loading_character
Login()
..()
var/save_name = "Players/[ckey].sav"
if(fexists(save_name))
// You can do something here to ask if they want to load or not, I'm just doing it automatically.
src.Load()
else
// Do stuff for new characters here.


Now you'll want to set world/mob to /mob/loading_character, to set the default mob to that type. Assuming you've properly moved your player-based stuff into something like /mob/player you'll be able to distinguish between a playing mob and a loading mob.

You'll also want to keep in mind that when creating a new character you'll want to create a new /mob/player (or whatever you use) and set the player's client.mob variable to that new mob.

// ... code
var/mob/player/new_player = new()
new_player.name = src.name
var/mob/old_mob = src.client.mob
src.client.mob = new_player
del(old_mob) // Cleaning up, even though the garbage collector would probably catch it if you did things properly.


I'm sure this is enough information to get you started on the system specific to your needs :).