ID:161617
 
This is the code I have for my save and load procs, but every time I manually call Load() it logs me out of the game and back in again and doesn't even load my Location, so if I call Load() inside Login() it goes into an infinite loop of logging in... I've seen lots of save file codes but they all do what mine's doing only mine's not working properly..

I've tried declaring the save and load procs in different places and calling them at different times but it's just not working

proc
Save()
var/savefile/F=new("Save/[usr.ckey]")
F["usr"]<< usr
F["x"]<< usr.x
F["y"]<< usr.y
F["z"]<< usr.z
Load()
if(fexists("Save/[usr.ckey]"))
var/savefile/F=new("Save/[usr.ckey]")
var
x
y
z
F["usr"]>> usr
F["x"]>> x
F["y"]>> y
F["z"]>> z
usr.loc= locate(x,y,z)


mob/verb
Loadit()
set category="Other"
Load()

Saveit()
set category="Other"
Save()


When I load it manually using the second code it gives me this error message:

BYOND Error:(Sfile.cpp,1170) failed to open file:
BYOND Error:(Sfile.cpp,1170) Save\
proc name: Save (/proc/Save)
usr: Player (/mob)
src: null
call stack:
Save()
Player (/mob): Logout()
Load()
Player (/mob): Loadit()
Sweep wrote:
>       F["usr"]<< usr


Whenever your client connects to a mob, Login() is called. This line of code pulls a mob out of the savefile and connects your client to it. If you want to use your system like this, I recommend you create a special /mob/login type and edit its Login() proc to do the savefile-loading, instead of doing it in the Login() proc of every mob. Then you make make world/mob = /mob/login (so that clients by default will connect to /mob/login-based mobs), and do all of your character handling within that type.

Also, your Save()/Load() procs are messed up. They shouldn't be global; instead, they should belong to your /mob type or something, and you should reference the mob's vars via src, instead of usr, so that you "No put usr in proc."

Hiead
In response to Hiead
Thanks for your help, but is there any way I can load the entire mob without it calling Login() every time?
In response to Sweep
Sweep wrote:
Thanks for your help, but is there any way I can load the entire mob without it calling Login() every time?

Loading a mob with the key var defined is going to log that user into that mob. This is actually desirable behavior.

The problem is, you need two Login() procs do the job. You need a special mob type for when users first log in:

world
mob = /mob/new_arrival

mob/new_arrival/Login()
// don't call ..() here

// do all the loading foo here
Load()


Lummox JR
In response to Lummox JR
I did that and it was working all right for a while but then for some reason now it does the same infinite loop thing but with the new_arrival/Login() and completely skips the regular Login()