ID:138911
 
Code:
mob
Login()
//if(save==1)
if(src.LoadProc())
else
switch(alert("What race would you like to be?",,"Wizard","Red Court Vampire"))
if("Wizard")
src.icon='Players.dmi'
src.icon_state="Wizard"
else
src << "The Red Court Race is not yet available."
src.name = input("Choose a name for yourself.") as text
if(lentext(name) < 2)
src << "Your name must have more than 2 letters in it."
else if(lentext(name) > 10)
src << "Your name must have less than 10 letters in it."
else
src << "You have now been named."
src.loc=locate(5,5,1)
src.AdminCheck()

mob
Logout()
src.SaveProc()
del src



mob/proc/SaveProc()
var/FileName="Players/[ckey(src.key)].sav"
if(fexists(FileName)) fdel(FileName)
var/savefile/F=new(FileName)
F["Admin"]<<src.Admin
F["Health"]<<src.Health
F["MaxHealth"]<<src.MaxHealth
F["Energy"]<<src.Energy
F["MaxEnergy"]<<src.MaxEnergy
F["Strength"]<<src.Strength
F["Endurance"]<<src.Endurance
F["Power"]<<src.Power
F["Resistance"]<<src.Resistance
F["Accuracy"]<<src.Accuracy
F["Dodge"]<<src.Dodge
F["Exp"]<<src.Exp
F["Healing"]<<src.Healing
F["Recovery"]<<src.Recovery
F["HealthMod"]<<src.HealthMod
F["EnMod"]<<src.EnMod
F["StrMod"]<<src.StrMod
F["EndMod"]<<src.EndMod
F["PowMod"]<<src.PowMod
F["ResMod"]<<src.ResMod
F["AccMod"]<<src.AccMod
F["DodgeMod"]<<src.DodgeMod
F["HealMod"]<<src.HealMod
F["RecovMod"]<<src.RecovMod
F["LastX"]<<src.x
F["LastY"]<<src.y
F["LastZ"]<<src.z
save=1
src<<"Character Saved..."


mob/proc/LoadProc()
var/FileName="Players/[ckey(src.key)].sav"
if(fexists(FileName))
var/savefile/F=new(FileName)
F["Admin"]<<src.Admin
F["Health"]<<src.Health
F["MaxHealth"]<<src.MaxHealth
F["Energy"]<<src.Energy
F["MaxEnergy"]<<src.MaxEnergy
F["Strength"]<<src.Strength
F["Endurance"]<<src.Endurance
F["Power"]<<src.Power
F["Resistance"]<<src.Resistance
F["Accuracy"]<<src.Accuracy
F["Dodge"]<<src.Dodge
F["Exp"]<<src.Exp
F["Healing"]<<src.Healing
F["Recovery"]<<src.Recovery
F["HealthMod"]<<src.HealthMod
F["EnMod"]<<src.EnMod
F["StrMod"]<<src.StrMod
F["EndMod"]<<src.EndMod
F["PowMod"]<<src.PowMod
F["ResMod"]<<src.ResMod
F["AccMod"]<<src.AccMod
F["DodgeMod"]<<src.DodgeMod
F["HealMod"]<<src.HealMod
F["RecovMod"]<<src.RecovMod
src.loc=locate(F["LastX"],F["LastY"],F["LastZ"])
src<<"Character Loaded..."
return 1


Problem description:
I am trying to get this to save a character when they log out, and when they return, if they have a save file, it will load otherwise they will be prompted to create a character.

I took the save code from Falacy's tutorial on it, and tried to implement it here, but for some reason it simply won't work. I get no errors, but it will not load. I'm rather stumped, as I'm new to coding, so if anyone could help me resolve this I'd be much obliged.
You're writing the file in your load proc. You need to use:

F[]>>stat

Not:

F[]<<stat
In response to Robertbanks2
Well I changed that up, but now it still won't load the character save. I'm thinking I may have set something up incorrectly for when the player logs in. I'm not sure what though, because I'm still getting 0 errors/warnings.
In response to Afterschaaf
My advice is to start from scratch and manually figure out how the saving/load works.
In response to Lugia319
I've looked over what the Blue Book has to say on Saves, but it is escaping me. Perhaps because I've been staring at code for most of the day, but I'd be grateful to whomever can help me resolve this problem.
In response to Afterschaaf
Alright, so I edited the code, and read over what the Blue Book had to say and this is what I have so far.

mob/var/savefile/F=new(ckey)

mob/proc
SaveProc()
Write(F)
F["X"] << src.x
F["Y"] << src.y
F["Z"] << src.z
F["Admin"]<< src.Admin
F["Health"]<< src.Health
F["MaxHealth"]<< src.MaxHealth
F["Energy"]<< src.Energy
F["MaxEnergy"]<< src.MaxEnergy
F["Strength"]<< src.Strength
F["Endurance"]<< src.Endurance
F["Power"]<< src.Power
F["Resistance"]<< src.Resistance
F["Accuracy"]<< src.Accuracy
F["Dodge"]<< src.Dodge
F["Exp"]<< src.Exp
F["Healing"]<< src.Healing
F["Recovery"]<< src.Recovery
F["HealthMod"]<< src.HealthMod
F["EnMod"]<< src.EnMod
F["StrMod"]<< src.StrMod
F["EndMod"]<< src.EndMod
F["PowMod"]<< src.PowMod
F["ResMod"]<<src.ResMod
F["AccMod"]<< src.AccMod
F["DodgeMod"]<< src.DodgeMod
F["HealMod"]<< src.HealMod
F["RecovMod"]<< src.RecovMod
del(src)

LoadProc()
Read(F)
F["X"] >> src.x
F["Y"] >> src.y
F["Z"] >> src.z
F["Admin"]>>src.Admin
F["Health"]>>src.Health
F["MaxHealth"]>>src.MaxHealth
F["Energy"]>>src.Energy
F["MaxEnergy"]>>src.MaxEnergy
F["Strength"]>>src.Strength
F["Endurance"]>>src.Endurance
F["Power"]>>src.Power
F["Resistance"]>>src.Resistance
F["Accuracy"]>>src.Accuracy
F["Dodge"]>>src.Dodge
F["Exp"]>>src.Exp
F["Healing"]>>src.Healing
F["Recovery"]>>src.Recovery
F["HealthMod"]>>src.HealthMod
F["EnMod"]>>src.EnMod
F["StrMod"]>>src.StrMod
F["EndMod"]>>src.EndMod
F["PowMod"]>>src.PowMod
F["ResMod"]>>src.ResMod
F["AccMod"]>>src.AccMod
F["DodgeMod"]>>src.DodgeMod
F["HealMod"]>>src.HealMod
F["RecovMod"]>>src.RecovMod


However I am getting this error.

Save.dm:105:error: =: expected a constant expression

It is referring to that top string where it says

mob/var/savefile/F=new(ckey)

Any ideas?
In response to Afterschaaf
You cannot create a new savefile outside of a proc like that.

Also, do not call Read() and Write() directly, as it will mangle your savefiles.

Garthor wrote up a very good way to handle saving which can be found here: [link]
In response to LordAndrew
Well I was hopeful, but that didn't help me at all. It said 'mob' was an undefined variable and told me that x, y, and z were not allowed there. It also said F was an undefined variable.

Yippie.

I hate saves.
In response to Afterschaaf
LordAndrew posted the most correct, to my knowledge of how to properly save files, read it.
In response to Afterschaaf
Use the client not the mob.