ID:141232
 
Code: Saving vars to savefile.
mob
Write(savefile/F) // Write proc
..()
F["last_x"] << x // saves your x location on the map
F["last_y"] << y // saves your y location on the map
F["last_z"] << z // saves your z location on the map
F["worn"] << src.worn
Read(savefile/F)
..()
var/last_x // var defined
var/last_y
var/last_z
F["last_x"] >> last_x // reads your x location on the map
F["last_y"] >> last_y // reads your y location on the map
F["last_z"] >> last_z // reads your z position on the map
F["worn"] >> src.worn
src.loc = locate(last_x, last_y, last_z) // locates you to your last map location

//The 'worn' var :
mob/var/worn = 0


Problem description: Coding\Slot Save Login System.dm:250:error:src.worn:undefined var & Coding\Slot Save Login System.dm:259:error:src.worn:undefined var

It highlights both of the worn vars in the save files. How do i make it so that it save the vars?


Could someone please help me with this? As i am getting no reply/response at all.
Y'know you could just not overwrite Write() and Read() and just call them in a Save() proc? Way easier, plenty of saving demos to demonstrate this. You don't need to save any non-temp variables by hand.

As for your error, it should work, goodness knows what the hell you've done wrong.
Also, you're writing the var in your Read().
In response to Mysame
Mysame wrote:
Y'know you could just not overwrite Write() and Read() and just call them in a Save() proc? Way easier, plenty of saving demos to demonstrate this. You don't need to save any non-temp variables by hand.

The coordinate vars aren't saved by default, therefore Write() and Read() need to be overridden in order to add processing them when object saving/loading; a better method than doing it elsewhere. As for his worn var, yes, it should be already handled by the default procedures (called with ..()) as with the rest of the 'normal' vars.
Hmmm, still don't get it. Because it should work. Anyone else who can see the problem here?
You're promoting exactly what the rest of us are telling him not to do. Nice job being counter-productive ^-^ And yes, you can save a mob's x,y,z vars directly to the savefile and then load them directly from the savefile. That's what the locate() proc is for.

mob/Write(savefile/F)
if(fexists(F)) fdel(F)
var/savefile/s = new(F)
s["loc_x"] << src.x
s["loc_y"] << src.y
s["loc_z"] << src.z
return ..()

mob/Read(savefile/F)
if(fexists(F))
var/savefile/s = new(F)
if(!src.Move(locate(s["loc_x"],s["loc_y"],s["loc_z"])))
src.loc = locate(1,1,1) //whatever location you want
return ..()


P.S.
Obviously his worn variable is for wearable items in his game. It's right in the name.
In response to Spunky_Girl
If you use Move() there is a chance that it will fail. So should either just use loc, or put some kind of check to see if it passed and try a different location.
In response to T3h P3ngu1n
If no available clear location is found, ideally, for such cases you'd use a proc that sets the loc and calls Entered() and Exited() (without checking Exit()/Enter(), so it never fails), so it still sets those movement procs in motion.