ID:1762422
 
(See the best response by Reformist.)
world
New()
log = file("error.txt")
..()
spawn(14)
spawn()autosave()
Del()
for(var/mob/M in world)
if(M.client)del M.client
del M
..()
proc
autosave()
set background=1
sleep(1800)
for(var/mob/player/M in world)
if(M.client)
M.client.SaveMob()
autosave()


Just out of curiosity, this is a stupid way to save right? autosave() is taking up a lot of processing. I should just do something like this right:

mob
player
Login()
spawn(10)
src.client.saveMob()
return ..()
Del()
src.client.saveMob()
return ..()


Best response
Read() and Write() are very CPU intensive by nature, so yes, saving automatically every 3 minutes is quite a bad move.

You don't need the return ..(), because that already happens by default unless ..() is called manually earlier.

Saving on mob deletion is fine, but why would you need to save the player 1 second after it logs in?

Saving only really needs to be done on Logout() typically, but you can add manual save calls for significant gameplay achievements just to make sure they're absolutely saved.

Another thing you may want to look into is keeping lists, such as all players logged in, that way you don't have to loop through world when looking for a small number of specific entities.
If the game were to crash, would it still save if I were to have the above code in place?
In response to SinfulPhoenix
Dream Daemon tries its hardest to collect information and end the server as gracefully as possible, so it shouldn't be an issue.
I've had problems with crashing. Server stays up for a random time between 1-15 hours before crashing. Figured it was due to bad coding, so I've been recoding things to hog less CPU. While the server speed is gradually improving, the crashing isn't stopping. Though I've noticed the server doesn't seem to crash when hosted on a shell.