ID:2126831
 
(See the best response by Kaiochao.)
Code:
world
name = "Egg World"
mob = /mob/LobbyPlayer


client/New()
if(usr) return ..() //reconnecting to existing mob
else
var/player_sav = "players/[ckey].sav"
if(length(file(player_sav))) //if player savefile exists
var/savefile/F = new(player_sav) //open it
F["mob"] >> usr
F["loc"] >> usr.loc
return ..() //creates a new mob if necessary

//The player is connected to this mob if they do not have a save file present.
mob/LobbyPlayer
icon = 'player.dmi'
icon_state = "move"
Login()
..()
usr << "Welcome! I see it's your first time here!"
usr << "Let's get you started!"
client.mob = new/mob/Player(usr.loc)
del src

mob/Player
icon = 'player.dmi'
icon_state = "move"
step_size = 8;
step_x = 0;
step_y = 16;
bound_x = 8;
bound_y = 0;
bound_width = 16;
bound_height = 16;

var
things = 0;
money = 0;

Logout()
var/player_sav = "players/[ckey].sav"
var/savefile/F = new(player_sav)
F << src
F["mob"] << src
F["loc"] << src.loc
del src


Problem description:
Okay, so I have a dummy mob "LobbyPlayer" set up to handle the player if they don't have a savefile present. After that, I create the actual Player mob and assign it to the client.mob. When the Player mob for that client logs out, it saves the mob. When a client tried to connect, it loads the mob.

My problem is that loading the mob doesn't seem to call New() or Login() on the mob. So for instance if I wanted in the future to change the code to
step_size = 4
then if a savefile is present, the game is going to load the old step_size that was saved and not the new value. How can I set these static/default values so that they are set after the mob is loaded from the file? I would like to not make old savefiles invalid and i would like to not have to manually pick and choose which things I want to save.

Best response
When a mob is loaded, its New() is called, then its Read(), and if key was loaded as a key of a currently connected client, Login() is called.

You can reset step_size after calling ..() in Read(), including in Login(), but it's more appropriate in Read().

You might want to keep track of savefile versions, so you can respond to older save formats.

Also, it's unnecessary to save twice, so remove that F["mob"] << src line.