ID:174035
 
Hey, my save works OK for now, but I also want it to save when the player logs out. Here is what I have now:

mob
proc
SaveChar(mob/M as mob)
var/savefile/F = new("players/[src.key].sav")
F["name"] << name
F["X"] << src.x
F["Y"] << src.y
F["Z"] << src.z
F["Mob"] << src.client.mob
src << "You have saved your game >>data!"
src.Save_Cycle()
return
mob
verb
Save()
src.SaveChar()
return

mob
proc
Save_Cycle()
sleep(1200)
src.SaveChar()
return

Now I tried this:

mob/Logout()
src.SaveChar()

but that gave me errors when the player logs in and when they log out. The code WORKS, it saves, but the error message is still there. Can anyone help me please?
</<></<></<></<></< >
Shades wrote:
Hey, my save works OK for now, but I also want it to save when the player logs out. Here is what I have now:

mob
proc
SaveChar(mob/M as mob)
var/savefile/F = new("players/[src.key].sav")
F["name"] << name
F["X"] << src.x
F["Y"] << src.y
F["Z"] << src.z
F["Mob"] << src.client.mob
src << "You have saved your game >>data!"
src.Save_Cycle()
return
mob
verb
Save()
src.SaveChar()
return

mob
proc
Save_Cycle()
sleep(1200)
src.SaveChar()
return

Now I tried this:

mob/Logout()
src.SaveChar()

but that gave me errors when the player logs in and when they log out. The code WORKS, it saves, but the error message is still there. Can anyone help me please?

Well, perhaps you could share us this error message?
In response to Wanabe
Id have to re-create the error and I rewmoved it. I just put it to reguarl save and 1200 sec saving.
In response to Shades
This is the problem line:

<code>F["Mob"] << src.client.mob</code>

Normally this will work fine. But in Logout(), client is null; because it's actually called AFTER the client leaves.

It's pretty redundant anyway, because src.client.mob is exactly the same as src. Just use the following line instead, and it should work fine:

<code>F["Mob"] << src</code>
In response to Crispy
Crispy, that works well to a point. Thank you. Now the player logs in right, and NO error messages!

But now when the player logs in, their icon is gone, all they have is thier overlays. Here is my loading code:

mob
proc
Continue_Game(mob/M as mob)
var/savefile/F = new("players/[src.key].sav")//loads from the players save file
var/X
var/Y
var/Z
var/mob/newmob = new()
F["name"] >> name
F["X"] >> X
F["Y"] >> Y
F["Z"] >> Z
F["Mob"] >> newmob
newmob.loc = locate(X,Y,Z)
del(src)
world << "[src.name] has logged in!"

Can you help me with this crispy? Thank you!
In response to Shades
One of the big problems I see is that your still using src even after youve defined the mob as M in the function declaration. It should be << M.Var not src.Var That way your saving the mob passed into the function not the src of the function.

Other than that I wouldnt save the mob at all. I save every var individually so I make sure everything gets put back where its spose to. =)
In response to Aridale
Everything works fine. Lol, here was the trouble:

mob
Login()
src.icon_state = ""
src.icon = ""

the icon one shouldnt of been in there. Thanks for the help!
In response to Shades
Ha, it's always the simple little things isn't it? =) Glad I could help!