ID:2363564
 
Code:
mob/proc
loadprocess()
var/whitelist = list("icon","overlays") // this what it should not save
var/savefile/f = new("Saves/players/[src.ckey].sav")
for(var/v in src.vars)
if(!issaved(src.vars[v]) || (v in whitelist))
continue
f[v] >> src.vars[v]


mob/var/vartest = "Mzxckasnfkanjnbj"
mob/verb/CheckVar()
world<<"[vartest] + 1")


Problem description: I'm having a problem with this. Then I create a new var and I have a save file, then I try to load the character the new var value will be none.
I tried to make a new var and load the character, I just saw the " +1" in the chat.
How to fix this?
The problem is you're looping through src.vars instead of f.dir. The savefile will not have saved anything that hasn't been changed from its default value, so you're loading a value the savefile doesn't have.

var/whitelist = list("icon","overlays") // this what it should not save
var/savefile/f = new("Saves/players/[src.ckey].sav")
for(var/v in f.dir)
// wrap this in a try/catch so if we try to load a var src doesn't have, nothing happens
try
if(!issaved(src.vars[v]) || (v in whitelist))
continue
f[v] >> src.vars[v]
catch // empty catch; we don't care
In response to Lummox JR
i have tried to place try and catch but the error still happen.
I placed in the save and load but then I create a new var that did not exist in save file the value of the var will be none or ""
What does your load routine look like now?
In response to Lummox JR
        var/savefile/f = new("Saves/players/[src.ckey].sav")
if(f)
try
for(var/v in src.vars)
if(!issaved(src.vars[v]) || (v in whitelist))
continue
f[v] << src.vars[v]
catch

and f[v] >> src.vars[v], load, so every time then the mob logins the proc load is called
Read my post above again. I said you need to loop through f.dir, not through src.vars. The values in f.dir are the actual vars in the savefile.

Also, the try/catch goes inside the for loop, not outside, because you don't want it to bail if it has a problem, just skip one variable. The code I posted has all of this, so you should just use that.
In response to Lummox JR
OHH, sorry my lack of attention caused this.

Now I understand what you have said, thank you Lummox it's not having any problems now.