ID:264988
 
Code:
mob
proc
Save()
var/savefile/F = new("SaveFiles/[src.ckey].sav")

F["gamerid"] << src.name
F["Points"] << src.Points
F["Delt"] << src.Delt
F["Damage"] << src.Damage
F["KOs"] << src.KOs
F["Defeats"] << src.Defeats

F["Shadow"] << src.Shadow
F["Rouge"] << src.Rouge
F["Gamma"] << src.Gamma
F["Chaos"] << src.Chaos
F["Blaze"] << src.Blaze
F["Silver"] << src.Silver
F["Shade"] << src.Shade
F["Espio"] << src.Espio
F["Mighty"] << src.Mighty
F["Charmy"] << src.Charmy
F["Gemerl"] << src.Gemerl
F["MetalSonic"] << src.MetalSonic
F["SSonic"] << src.SSonic
F["STails"] << src.STails
F["SKnuckles"] << src.SKnuckles
F["SAmy"] << src.SAmy
F["SShadow"] << src.SShadow
F["DSonic"] << src.DSonic

F["SonicDamage"] << src.SonicDamage
F["TailsDamage"] << src.TailsDamage
F["KnucklesDamage"] << src.KnucklesDamage
F["AmyDamage"] << src.AmyDamage
F["ShadowDamage"] << src.ShadowDamage



Load()
var/savefile/F = new("SaveFiles/[src.ckey].sav")

F["gamerid"] >> src.name
F["Points"] >> src.Points
F["Delt"] >> src.Delt
F["Damage"] >> src.Damage
F["KOs"] >> src.KOs
F["Defeats"] >> src.Defeats

F["Shadow"] >> src.Shadow
F["Rouge"] >> src.Rouge
F["Gamma"] >> src.Gamma
F["Chaos"] >> src.Chaos
F["Blaze"] >> src.Blaze
F["Silver"] >> src.Silver
F["Shade"] >> src.Shade
F["Espio"] >> src.Espio
F["Mighty"] >> src.Mighty
F["Charmy"] >> src.Charmy
F["Gemerl"] >> src.Gemerl
F["MetalSonic"] >> src.MetalSonic
F["SSonic"] >> src.SSonic
F["STails"] >> src.STails
F["SKnuckles"] >> src.SKnuckles
F["SAmy"] >> src.SAmy
F["SShadow"] >> src.SShadow
F["DSonic"] >> src.DSonic

F["SonicDamage"] >> src.SonicDamage
F["TailsDamage"] >> src.TailsDamage
F["KnucklesDamage"] >> src.KnucklesDamage
F["AmyDamage"] >> src.AmyDamage
F["ShadowDamage"] >> src.ShadowDamage

for(var/mob/M in world)
if(M.Player== 1)
M << "<b><font color = green>[src] has joined us!"
usr << sound(null)
if(src.Sound == 1)
usr << sound('Ok.wav')
src.MenuDelay = 1
src.Points = round(src.Points)
spawn(3)
src.MenuDelay = 0





var/Pointsz = ((((src.Delt*2)-(src.Damage))/3) + ((src.KOs*70)-(src.Defeats*40)))
Pointsz = round(Pointsz,1)
if(Pointsz <0)
Pointsz = 0
if(Pointsz >999999)
Pointsz = 999999
src.RankPoints = Pointsz
src.SkillLevelCheck()
winset(src,"Silver Rings","text=\"Silver Rings: [src.Points]\"")




if(src.Rank == 1)
src.Fighter = 0
usr.loc = locate(68,7,1)
if(src.Music == 1)
usr << sound('Tutorial.s3m',1)
else
src.ShowCharacterSelect()
src.Fighter=1


Problem description: For some reason every now and again it will load but instead it wont load properly. Instead of your name being the loaded name its your key. Also all of your variables are the defaults. No idea why this happens at all.

Instead of loading and saving every variable in the savefile. You can just save and load the mob.

var/savefile/F = new("awesomefile.sav")
F["mob"] << src


This will save all the variables that belong with the mob that is being saved.
In response to Hashir
I know that but it causes more problems than its worth. Cause then I have to reset a large amount of variables on login
In response to Inferno L Flames
Any variables that you don't want to save can be defined under the tmp label, like so:

var/tmp/Frozen

This will create a variable that is ignored by the default read()/write() procs when saving to savefiles.

Also, if you want to loop through all of the players, use for(var/client/C), not for(var/mob/M in world). This will check only the clients, without looping through every mob and making sure it's a player.
In response to Robertbanks2
what about built in var like x y z and crap
In response to Inferno L Flames
mob/Write()
..()
F["xx"]<<x
F["yy"]<<y
F["zz"]<<z

mob/Read()
..()
var/xx
var/yy
var/zz
F["x"]>>xx
F["y"]>>yy
F["z"]>>zz
loc=locate(xx,yy,zz)


Or something like that. Either way, you should read up on savefiles before making a new save system, they tend to be pretty finicky unless you understand them thoroughly.
In response to Robertbanks2
this is my old system this is the first time this has happen which is why i was so confused and you did the opposite of what i want I wanted to NOT include xyz position and built in variables cept name
In response to Inferno L Flames
A mob's location isn't saved by default, I assumed you knew this and were asking how to save it.

The best I can guess for the issue of giving you your key as your name is that you're doing it elsewhere, not in the saving.
In response to Robertbanks2
I'll try the different type and see what happens in a soon to be update. Then if it still dosnt Well I'll be really confused but thanks
In response to Robertbanks2
Robertbanks2 wrote:
>
> mob/Write()
> ..()
> F["xx"]<<x
> F["yy"]<<y
> F["zz"]<<z
>
> mob/Read()
> ..()
> var/xx
> var/yy
> var/zz
> F["x"]>>xx
> F["y"]>>yy
> F["z"]>>zz
> loc=locate(xx,yy,zz)
>

Or something like that. Either way, you should read up on savefiles before making a new save system, they tend to be pretty finicky unless you understand them thoroughly.


You don't need to define temporary vars to load x, y and z. You can do something like:

loc = locate(F["x"], F["y"], F["z"])
In response to Hashir
I figured as much, but wasn't 100% sure so I did it the way I knew for sure would work. Thanks for the confirmation.
In response to Inferno L Flames
I just thought about something. Could this glitch be happening cause I tell it to save when a person logs out. Could the glitch happen when the game doesn't close properly?