ID:2546914
 
Code:
mob/combative/player/proc
Save_Player()
if(initialized && named)
var/savefile/D = new(SAVEFILE_PATH("timer"))
D["seconds"]<<client.seconds
D["tracked"]<<client.tracked
D["hours"]<<client.hours
D["minutes"]<<client.minutes
D["days"]<<client.days
D["weeks"]<<client.weeks
D["heartofgold"]<<client.heartofgold
D["customtext"]<<client.customtext
var/savefile/Z = new(SAVEFILE_PATH("[current_slot]o"))
Z["ovlay"]<<overlays
Z["name"]<<savedname
Z["rank"]<<rank
Z["village"]<<village
Z["level"]<<level
Z["icon"]<<icon_name
var/savefile/F = new(SAVEFILE_PATH(current_slot))
Last_x = x
Last_y = y
Last_z = z
F << src
mob/proc
Load_Player(var/slotty)
if(initialized)return
var/savefile/F = new(SAVEFILE_PATH(slotty))
var/mob/M = src
F >> M
M.SetLoadStuff(F,slotty)
SetLoadStuff(var/savefile/F,var/currentslot)
initialized = 1
loc = locate(Last_x,Last_y,Last_z)
current_slot=currentslot
hotslot_stuff()
Check_ScreenLight()
client.perspective=MOB_PERSPECTIVE
client.eye=client.mob


Problem description:

This is my nasty Save and Load code. I wrote this when I was a very inexperienced programmer, and tbh, I don't really know how to fix it because I still don't quite understand how Byond handles Saving and Loading.

The issue I'm having is, whenever a player logs out, which procs Save_Player(), the server freezes for a few seconds. Same thing happens when a character logs in and loads Load_Player(). I have absolutely no idea why this is happening or how to fix it. Any ideas?

Thanks for your time!

Edit: would having a bunch of "garbage variables" in my source code be a potential issue? In other words, would going through my source, and making sure every variable that should be marked tmp is tmp, and deleting old variables no longer being used? I don't know if that is inflating save files and making the Read/Write time longer?
Yes.

I ran into this issue years ago and the solution was to not save the entire mob. You'll write entire icons into the savefile.

Pick and choose the variables you want/need to save and write them directly.
You will also want to write a conversion procedure for all existing saves on your game to convert them to the new format.