ID:156323
 
Well, I am having some issues with savefiles upon logging in and out...mostly in(loading). It seems that the savefile is trying to load the mob's contents and datums before it even establishes the mob/client. It is giving me errors such as src: null and usr: null, cannot modify null.value, and saying that it cannot load certain things. I am wondering how to stop this...so how do I prioritize saving/loading?

If anything is unclear, please inform me and I will explain further to the best of my ability.
This sounds a bit strange, but you could incorporate...

client/New()
.=..()
src.mob.Load()
In response to CauTi0N
The only issue with this is that I have a slot saving system, so you pick which save you want from a selection screen, meaning the mob is already logged in and mostly loaded. Which is why I don't understand this.
In response to Albro1
That's impossible - the client is created at runtime and cannot be changed. Do you mind posting the place where your code is located, and the exact errors applied? It's hard to check anything without code. Also, I recommend #define DEBUG usage in this situation.
In response to CauTi0N
I use #define DEBUG.

Read & Write:
mob
Write(savefile/F)
F.dir.Remove(overlays)
..()
Read(savefile/F)
F.dir.Remove(overlays)
..()
winset(src,"default.child1","left=main")


Save:
proc
Save(mob/player/M,slot as text)
slot=M.slot
var/savefile/F=new("World_Files/players/[M]/[M]_[slot].sav")

M.Write(F)
M.Overlay_Refresh()
M<<"<center><font color=red>\[Game Saved.\]</font></center>"


Load(Stripped down of unnecessary things):
    Load(mob/player/M)
var/slot=M.slot
if(fexists("World_Files/players/[M]/[M]_[slot].sav"))
var/savefile/F=new("World_Files/players/[M]/[M]_[slot].sav")

M:Read(F)
else del(M)
winset(M,null,{"
login.new_load_1.is-disabled=true;
login.new_load_2.is-disabled=true;
login.new_load_3.is-disabled=true;
login.delete_1.is-disabled=true;
login.delete_2.is-disabled=true;
login.delete_3.is-disabled=true
default.is-maximized=true;
"}
)

var
x = 10
y = 6
M.loc=locate(x,y,2)
M.client.AddSkillsHuds()
M.UpdateQuests()
M.UpdateInventory()
M.UpdateSkills()
M.Refresh_Stat_Output()
M<<"<center><font color=red>\[Login Successful.\]</font>"
Online+=M
world<<"<center><font color=red>\[[M] has logged in.\]</font>"

Save(M)


Errors(WARNING: Long):

usr: null
src: Asauchi (/obj/Inv_Icons/Sword)
call stack:
Asauchi (/obj/Inv_Icons/Sword): New(null)
the player (/mob/player): Read(World_Files/players/Albro1/Alb... (/savefile))
Albro1 (/mob/player): Read(World_Files/players/Albro1/Alb... (/savefile))
Load(Albro1 (/mob/player))
Albro1 (/mob/player): LoadChar1()
runtime error: Cannot read null.skill_items
proc name: New (/skills/New)
usr: null
src: Shikai (/skills/Shikai)
call stack:
Shikai (/skills/Shikai): New(null, null)
Shikai (/skills/Shikai): New(null)
Albro1 (/mob/player): Read(World_Files/players/Albro1/Alb... (/savefile))
Albro1 (/mob/player): Read(World_Files/players/Albro1/Alb... (/savefile))
Load(Albro1 (/mob/player))
Albro1 (/mob/player): LoadChar1()
runtime error: Cannot read null.skill_items
proc name: New (/skills/New)
usr: null
src: Bankai (/skills/Bankai)
call stack:
Bankai (/skills/Bankai): New(null, null)
Bankai (/skills/Bankai): New(null)
Albro1 (/mob/player): Read(World_Files/players/Albro1/Alb... (/savefile))
Albro1 (/mob/player): Read(World_Files/players/Albro1/Alb... (/savefile))
Load(Albro1 (/mob/player))
Albro1 (/mob/player): LoadChar1()
runtime error: BYOND Error: bad mob
proc name: Read (/mob/Read)
usr: null
src:
call stack:
Read(World_Files/players/Albro1/Alb... (/savefile))
Load(null)
LoadChar1()
runtime error: bad client
proc name: Load (/proc/Load)
usr: null
src: null
call stack:
Load(null)
LoadChar1()




EDIT: As a side note, I have else del(M) there for testing. I wasn't sure where the savefile was screwing up, and that spot was my suspicion. It worked, however.
The client does not get logged into the mob until the key variable is read. A simple workaround is for you to simply put ..() BEFORE anything else in your Read() proc. A better method would probably to do any setup pertaining to the client in mob/Login().
In response to Garthor
Can you elaborate more on the client/New() part? With my current setup, I am not sure how to go about this. There are 3 slots that players can save in. Upon login, those files are accessed(If they exist), and used to show the name of the file. But once I click load, all of those errors show.
In response to Albro1
I didn't mention client/New() anywhere. The two solutions are to put ..() on the FIRST line of mob/Read(), or to put anything pertaining client information in Login().

Or, I guess you could also just have a separate proc to set up the client interface stuff, and call that explicitly after the mob is loaded, in wherever you load the mob.
In response to Albro1
May I ask what the point of using the directory variable is for? I just set the players' overlays and underlays variables to null before WRITING to the savefile and then re-adding the overlays and underlays when the saving is all done. There is simply no need for it at all in your Read() proc, since you removed it in your Write() proc.
In response to Spunky_Girl
Compatability with older savefiles.
In response to Garthor
I was unaware that that would be an issue o.O