ID:1950672
 
(See the best response by Ter13.)
Code:
mob
proc
Save()
var/savefile/S = new("[save_path]/[ckey].sav")
S["name"]<<name
S["X"]<<src.x
S["Y"]<<src.y
S["Z"]<<src.z
S["Mob"] << usr.client.mob
Load()
var/fname = "[save_path]/[ckey].sav"
if(fexists(fname))
var/savefile/S = new(fname)
var/mob/player/m=new()
src.client.mob=m
var/X
var/Y
var/Z
S["name"]>>name
S["X"]>>X
S["Y"]>>Y
S["Z"]>>Z
S["Mob"] >> m
usr.loc=locate(X,Y,Z)
m.client = src.client

turf
LoadingScreen
LoadCharacter
name = "Create"
icon = 'loadscreen.dmi'
icon_state = "Load"
Click()
usr.Load()


Problem description:

My issue is with the loc here ive tried calling Move() usr src mob directly....it just spawns me into black with no icon once i call load.... :( any ideas? the icon is specified under mob/player and the turf is indenented correctly i just cant tab in here lol.
No usr in proc ugh.
Best response
The reason this isn't working, is because you used usr. Usr is the last mob to have used a verb at the time the proc is called. In your case, the last mob to have done something will never be the mob that you just loaded, but rather the client's mob at the time the proc was called.

usr.client.mob



Stop and think about this for a second:

You are trying to save usr's client's mob. usr's client is the client connected to this mob. The client connected to this' mob's mob variable will be the mob. usr.client.mob will always be equal to usr... It's just slower and really, really silly.


Also, usr is not valid in procs like this. Even if it is working properly, it's not safe. You want to be using src.

It doesn't really make sense to have Load() on the mob. It kind of makes more sense to be part of the client. Also, you should take advantage of Read()/Write() when you can.

client
proc
LoadPlayer()
var/fname = "[save_path]/[ckey].sav"
if(fexists(fname))
var/savefile/S = new(fname)
var/mob/player/m
S >> m
mob = m
mob
proc
Save()
var/savefile/S = new("[save_path]/[ckey].sav")
S << src

Write(savefile/F)
..()
F["x"] << x
F["y"] << y
F["z"] << z

Read(savefile/F)
..()
var/x,y,z
F["x"] >> x
F["y"] >> y
F["z"] >> z
loc = locate(x,y,z) //would probably be good to use ForceMove here.

turf
LoadingScreen
LoadCharacter
name = "Create"
icon = 'loadscreen.dmi'
icon_state = "Load"
Click()
usr.client.LoadPlayer()
Thanks! im losing it....
In response to Ter13
Ter13 wrote:

It doesn't really make sense to have Load() on the mob. It kind of makes more sense to be part of the client.

I always handle saving and loading functions apart of the mob, and then I have separate saving and loading functions for the client.

Is this wrong? I figure saving/loading on mob makes sense, since you're saving and loading a mob. Then for client variables and such I'll have separate functions.
Saving makes sense on the mob. But loading doesn't. The reason for that is that the mob doesn't exist yet when you are calling load. Pulling the mob out of the savefile creates it, so the Load function has to be called before the mob ever exists.

This is why I recommend using Read() to handle special value loading from savefiles pertaining to specific objects. And Write() is useful for special value saving. A save function should only do two things: 1) load the savefile, 2) Put the mob in the savefile. Write() will be triggered by outputting the mob to the savefile. All the business of saving the mob's values should be handled in Write()
Ah, I see. Thanks.