ID:147260
 
Im making an Auto Saver for Deadron's character Handling (For Obvious reasons) But I cant get it to work with the following Code.
proc    
AutoSave()
sleep(300)
for(var/mob/Newchar/A in world)
A.Write()
world << "All characters were Automatically Saved."
spawn(300)
AutoSave()

It shows the MSG and everything, it just doesnt save, please help.
proc    
AutoSave()
sleep(300)
for(var/mob/Newchar/A in world)
A.Write()
world << "All characters were Automatically Saved."
spawn(300)
AutoSave()



takes apart the code,

wait for 30 secs
A = mobs of type Newchar
A.Write() // save proc ?!?
spam world "All characters were Automatically Saved."
in 30secs time run AutoSave()

have you checked the code for A.Write() ? this is where the game should save.

below is a nicer version of that code.
proc    
AutoSave()
for(var/mob/Newchar/A in world)
A.Write()
A << "All characters were Automatically Saved."
spawn(3000) AutoSave()

this code will save every 5 mins less CPU demanding than
your old code.
the draw back to this code, saves at startup (not that bad but still a draw back)

thinges you can do to this code to make it even better,
1, build a list of online users so that you do not save NPC's









In response to Madpeter
Only characters are mob/Newchar so that is already fixed.

Also, I thought Write() was the default save proc because apparently Write saves all variables, if not how does Deadron's Character Handling save?
In response to Metroid
Hello? I really need help... Please help...
In response to Metroid
There is no default save proc. You need to generate it yourself. If Daedron's doesn't come with a save proc you need to create your own. Like...

<code> client/proc/Save() var/savefile/F = new("/[src.ckey].sav") var/char_ckey = cKey(src.mob.name) F["/[ckey]/[char_ckey]"] << src.mob client/proc/Load(char_ckey) var/savefile/F = new("/[src.ckey].sav") F["/[ckey]/[char_ckey]"] >> src.mob </code>

That allows you to load and save.
In response to Vakir
So how does Deadron's Char Handling end up saving then? I have no save code in my eniter code...yet it saves. And I know it normally doesnt when I dont have DCH included.
In response to Metroid
Metroid wrote:
So how does Deadron's Char Handling end up saving then? I have no save code in my eniter code...yet it saves. And I know it normally doesnt when I dont have DCH included.

If you look in characterhanlding.dm, you'll find quite a lot of documentation for how to use the library, including documentation of the client/base_SaveMob() command...
In response to Deadron
Ive used that but it didnt work for whatever reason so thats why I went to posting this. I had that on for a while and I tested it by taking out my save from the folder waiting for the msg that its auto saved and a new version of my save never came up but when I logged out it did.
In response to Metroid
Also Deadron, Id like to note that I was doing this post because for some reason in my game my players have been reverted, and when I was looking at my Runtime Log, I noticed this

AutoSave()
runtime error: bad file
proc name: Write (/mob/Write)
source file: implementation.dm,45
usr: null
src: Metal babble man (/mob/Newchar)
call stack:
Metal babble man (/mob/Newchar): Write(null)
AutoSave()

Why am I getting that?