ID:975985
 
(See the best response by DarkCampainger.)
So I've been a lazy scrub for so long and just using libraries for saving mobs, so I decided to look into how savefiles work, but I'm encountering a bug in this experimental login system - when I load an existing character, instead of loading the mob, it jumps back to the start of Login().

Please note that I'm not going for efficiency here, I'm just playing around, and the use of goto is purely due to me not wanting to use loops in something I know nothing about.

mob
proc
Save()
if(saveslot==1)
var/savefile/F = new("Saves/[src.ckey] (1).save")
F["mob"] << src

if(saveslot==2)
var/savefile/F = new("Saves/[src.ckey] (2).save")
F["mob"] << src

if(saveslot==3)
var/savefile/F = new("Saves/[src.ckey] (3).save")
F["mob"] << src

Load1()
if(fexists("Saves/[src.ckey] (1).save"))
var/savefile/F = new("Saves/[src.ckey] (1).save")
F["mob"] >> src

Load2()
if(fexists("Saves/[src.ckey] (2).save"))
var/savefile/F = new("Saves/[src.ckey] (2).save")
F["mob"] >> src

Load3()
if(fexists("Saves/[src.ckey] (3).save"))
var/savefile/F = new("Saves/[src.ckey] (3).save")
F["mob"] >> src

Logout()
Save()
..()

Login()

Login
var/Action=input("Welcome to [world.name]! Please select an option below.","[world.name]") in list ("New Character","Load Character","Delete Character")
switch(Action)

if("New Character")
var/Slot=input("Which slot do you wish to create a new character in?","New Character") in list ("Slot 1","Slot 2","Slot 3")
switch(Slot)

if("Slot 1")

if(fexists("Saves/[src.ckey] (1).save"))
alert("You already have a character in slot 1! Please delete your old one or pick another slot!")
goto Login

else
NewChar(1)

if("Slot 2")

if(fexists("Saves/[src.ckey] (2).save"))
alert("You already have a character in slot 2! Please delete your old one or pick another slot!")
goto Login

else
NewChar(2)

if("Slot 3")

if(fexists("Saves/[src.ckey] (3).save"))
alert("You already have a character in slot 3! Please delete your old one or pick another slot!")
goto Login

else
NewChar(3)

if("Load Character")
var/Slot=input("Which slot do you wish to load a character from?","Load Character") in list ("Slot 1","Slot 2","Slot 3")
switch(Slot)

if("Slot 1")

if(!fexists("Saves/[src.ckey] (1).save"))
alert("You have no character in slot 1!")
goto Login

else
Load1()

if("Slot 2")

if(!fexists("Saves/[src.ckey] (2).save"))
alert("You have no character in slot 2!")
goto Login

else
Load2()

if("Slot 3")

if(!fexists("Saves/[src.ckey] (3).save"))
alert("You have no character in slot 3!")
goto Login

else
Load3()

if("Delete Character")
var/Slot=input("Which slot do you wish to delete a character from?","Delete Character") in list ("Slot 1","Slot 2","Slot 3")
switch(Slot)

if("Slot 1")

if(!fexists("Saves/[src.ckey] (1).save"))
alert("You have no character in slot 1!")
goto Login

else
fdel("Saves/[src.ckey] (1).save")
alert("Your character in slot 1 has been deleted!")
goto Login

if("Slot 2")

if(!fexists("Saves/[src.ckey] (2).save"))
alert("You have no character in slot 2!")
goto Login

else
fdel("Saves/[src.ckey] (2).save")
alert("Your character in slot 2 has been deleted!")
goto Login

if("Slot 3")

if(!fexists("Saves/[src.ckey] (3).save"))
alert("You have no character in slot 3!")
goto Login

else
fdel("Saves/[src.ckey] (3).save")
alert("Your character in slot 3 has been deleted!")
goto Login


mob
var/saveslot
proc
NewChar(Slot)

///////
Name
///////
var/newName=input("What will your name be? Please note that it can not be blank.","Character Creation") as text
if(newName=="")
goto Name
else
name=newName

saveslot=Slot
src.loc=locate(1,1,1)
Save()
.sav is the savefile extention, not .save
That made no difference whatsoever, the result is the same. I doubt .sav is official, the reference doesn't say you can't use whatever...
In response to NNAAAAHH
The extension doesn't actually matter.
In response to Shaoni
Try using Read(F) to load. When you do "F >> src", you're changing the client's mob to the mob inside the savefile. Whenever you change mobs, Logout and Login are called.
In response to Kaiochao
The problem was most likely that it would switch mob and thus run Login() again. I tried using Read and Write, but when I load a character now I just get a black screen. Probably not doing this correctly.

EDIT: I read something about x, y and z not being saved, could that be the problem here?
In response to Kaiochao
Best response
It has been said many times (even by Lummox JR himself) that calling Read() and Write() directly will lead to undefined behavior. It should be avoided.

To avoid re-calling Login(), you should create a mob subtype just for connecting players, and use that for loading. Then, when the actual player mob is loaded, its Login() process can do something completely different:
world/mob = /mob/Connection

mob
Connection
Login()
// [Character handling]

Player
Login()
// [Something else]

In response to DarkCampainger
Success. That fixed it! My location still wasn't being saved so I overwrote the Read() and Write() to do that manually, and it's working perfectly.