ID:847485
 
(See the best response by Lugia319.)
I'm getting this runtime error every time I try and use the Load button. Ill paste all of the codes that I think are related.

Runtime error: "runtime error: Cannot modify null.level.
proc name: LoadProc (/mob/proc/LoadProc)
usr: LastB (/mob)
src: null
call stack:
LoadProc()
LastB (/mob): loadcharacter()
the load (10,3,1) (/turf/load_options/load): Click(the load (10,3,1) (/turf/load_options/load), "MainWindow.MainMap", "icon-x=14;icon-y=16;left=1;scr...")


Load Character Proc:
mob
proc
loadcharacter()
if(!fexists("Players/[ckey(src.key)].sav"))
src << "You don't have a character on this server."
else
src.LoadProc()


Save/Load Procs:
mob/proc/SaveProc()
var/FileName="Players/[ckey(src.key)].sav"
if(fexists(FileName)) fdel(FileName)
var/savefile/F=new(FileName)
F["mob"] << src
F["Level"]<<src.level
F["Exp"]<<src.exp
F["Nexp"]<<src.nexp
F["HP"]<<src.health
F["MaxHP"]<<src.mhealth
F["Str"]<<src.str
F["Def"]<<src.def
F["Spi"]<<src.spi
F["Agi"]<<src.agi
F["LastX"]<<src.x
F["LastY"]<<src.y
F["LastZ"]<<src.z
src<<"Character Saved..."

mob/verb
Save()
src.SaveProc()


mob/proc/LoadProc()
var/FileName="Players/[ckey(src.key)].sav"
if(fexists(FileName))
var/savefile/F=new(FileName)
F["mob"] >> src
F["Level"]>>src.level
F["Exp"]>>src.exp
F["Nexp"]>>src.nexp
F["HP"]>>src.health
F["MaxHP"]>>src.mhealth
F["Str"]>>src.str
F["Def"]>>src.def
F["Spi"]>>src.spi
F["Agi"]>>src.agi
src.loc=locate(F["LastX"],F["LastY"],F["LastZ"])
src<<"Character Loaded..."
return


Login/Logout:
mob
Login()
if(src.LoadProc())
world<<"[src] has Returned"
else
src.loc=locate(9,10,1)
world<<"[src] has logged in."
spawn(-1) winset(src,"default","size=640x640; pos=100,100; is-maximized=true")
//The above winset() line is new
Logout()
world<<"[src] has logged out."
src.SaveProc()
del src



Turfs:
turf
load_options
layer = 6
mouse_opacity = 2

create
Click()
usr.newcharacter()

load
Click()
usr.loadcharacter()

delete
Click()
usr.deletecharacter()



Any help on this would be much appreciated.

Best response
God, why does everyone do the F[STAT] << thing?! Does no one know of Read/Write?

The problem probably comes from how you save the "mob". Since you "load" that first, it may be causing an error with a null src. Considering that the level is modified right after mob, that's my hunch. My advice to you - USE THE READ() AND WRITE() PROCS!
In response to Lugia319
Falacy's tutorial on saving and loading teaches it.
oh jeez... I just noticed that. Thanks Lugia! And the only reason I'm using the F(stat) thing is because that's the only way I know how to so far :P. It's because of Falacy's guide
Falacy's guide works the way it does because it's in its natural state. When you use a resource, don't edit it without saving a backup. That's my second piece of advice.

I'll also note that Falacy's method gets increasingly laborious as you increase the number of variables. I personally find that Read/Write cover everything extremely easily. In fact, the only time I've ever seen the modification to Write() is for the X,Y,Z in all the libs I've looked at (Deadron, Spunky, and even a few off-site resources)

Here's a link to Spunky's demo, I think you should find it easier to use than Deadron (Deadron is like Falacy Forum Account in that he likes to have his libraries all work together). Spunky's can stand alone.
Holy mother of god. I love you. I've been sitting here for like 3 hours trying to figure out the simplest of features. Thank you!