ID:2917273
 
Code:
mob
proc
LoadPlayer()
if(fexists("players/[src.ckey].sav"))
var/savefile/F = new("players/[src.ckey].sav")
Read(F)
for(var/stuff in src.V)
src.verbs += stuff
world<<"<font size=1><font color=red><B>Info: <font color=white>[src]([src.key]) has logged in..."
//src.loc = locate(xco,yco,zco)
src.cansave=1
(Players ||= new) += src // LOL this code o-o
//src.AutoSave() // this starts auto save for players when they hit load
src.logincrap()

SaveK()
var/savefile/F = new("players/[src.ckey].sav")
if(fexists(F)) fdel(F)
src.V = src.verbs
Write(F)

mob/verb/Savenow()
usr.SaveK()
usr<< "Your game has been saved."

mob/Write(savefile/F)
//store coordinates
//F ["saved_verbs"] << verbs
F ["saved_x"] << x
F ["saved_y"] << y
F ["saved_z"] << z
//store variables
..()
mob/Read(savefile/F)
var {saved_x; saved_y; saved_z}
//load coordinates
//F ["saved_verbs"] >> verbs
F ["saved_x"] >> x
F ["saved_y"] >> y
F ["saved_z"] >> z
//restore variables
..()
//restore coordinates
Move(locate(saved_x,saved_y,saved_z))

mob/proc/AutoSave()
set background = 1
src.SaveK()
spawn(3000)
src.AutoSave()

runtime error: cannot open savefile buffer saved_x for write
proc name: Write (/mob/Write)
source file: Naruto.dm,161
usr: (src)
src: the ddgh (/mob)
src.loc: (69,37,1) (/turf/grass/tiles/gs138)
call stack:
the ddgh (/mob): Write(players/kyubikitsune.sav (/savefile))
the ddgh (/mob): SaveK()
the ddgh (/mob): Savenow()

Problem description:
Receiving the runtime error and although it's not DM i figured it would help to separate it. I have a very basic save/load system and my knowledge on it is very limited. I've looked through the DM guide and can't find anything on this but I was experimenting so do ignore the stuff in // as it's probably very wrong lol. However, I'm not sure what the runtime error means, all i know is that it's related to "F ["saved_x"] << x" in the write section. Any help is appreciated, thank you!

Edit--------
Also worth mentioning that it creates two savs; one with my key and one without for some reason. I'm only intending to create one.



</<>
Okay so I did downgrade to version 514 and the error about the writing isn't an issue anymore however it's still making the .sav file when it shouldn't be and the autosave on logout isn't working so I'm assuming those are related.
You have spaces after your variable name in the savefile Read/Write procs. That needs to be fixed. Spaces are no good for variable names.
I appreciate the tip! I did get everything else working. Ig part of the Del() code outside the code shown above was deleting my mob before the actual mob deletion so there was no ckey to save. If anyone has any other tips on making this code better though I would appreciate it! :)
var list/players = new

world/New()
Autosaving()

proc/Autosaving()
set waitfor = FALSE
var mob/P
for()
sleep(3000)
for(P in players)
P.AutoSave()

mob/Login()
players.Add(src)

mob/Logout()
players.Remove(src)


Could do something like this to save some cpu, can also incorporate this pattern into many other things to get a decent speeds with lots of things happening/going on.

Your above method created a loop for each mob in the world using it. So 1,000 players would mean 1,000 active loops doing autosaving, while my above method allows for a single loop to handle every mob.