ID:147521
 
//I'm just starting to learn saving/loading and was wondering why the following coding results in runtime errors and how they may be fixed. (Copy&Paste)

world/mob=/mob/player
mob/player/Login()
src.main_menu()
mob/player/proc/main_menu()
var/savefile/S=new("Savefiles.sav")
S.cd="/[src.ckey]"
var/list/menu=new()
menu+="Create Character"
menu+=S.dir
menu+="Delete Character"
menu+="Logout"
var/selection=input("Welcome to Arcana! Please select one of the following options.")in menu
if(!selection) src.main_menu()
if(selection=="Logout") del(src)
if(selection=="Create Character") src.Create_Character()
if(selection=="Delete Character") src.Delete_Character()
else
S.cd="/[src.ckey]/[selection]"
S["mob"]>>src.client.mob


mob/player/proc/Create_Character()
src.name=input("Please enter a name.")as text
src.Save()

mob/player/proc/Delete_Character()
var/savefile/S=new("Savefiles.sav")
S.cd="/[src.ckey]"
var/list/menu=new()
menu+=S.dir
menu+="Cancel"
var/selection=input("Which character did you wish to delete?")in menu
if(!selection) src.Delete_Character()
if(selection=="Cancel") src.main_menu()
else
alert("This character will be permanently removed. Continue?","Verification","Yes","No")
if("Yes")
S.cd="/[ckey]"
S.dir.Remove(selection)
src.main_menu()
if("No")
src.Delete_Character()
mob/player/proc/Save()
var/savefile/S=new("Savefiles.sav")
S.cd="/[src.ckey]/[src.name]"
S["mob"]<<src.client.mob
What are the runtime errors, and on which lines do they occur?
In response to Crispy
-----------------------------------------------------------
runtime error: Cannot modify null.mob.
proc name: main menu (/mob/player/proc/main_menu)
usr: Xallius (/mob/player)
src: Xallius (/mob/player)
call stack:
Xallius (/mob/player): main menu()
Xallius (/mob/player): Login()
-----------------------------------------------------------
This error occurs when I attempt to load from a savefile.
In response to Xallius
It's complaining about the "src.client.mob" on the last line of main_menu(). Somehow src.client is null... which is, uh, strange.

Instead of that line, try something like this:

<code>var/mob/M S["mob"] >> M M.key=src.key del src</code>

If I remember correctly, setting the mob's key like that should log the client into it. You may have to mess around with it a little before it will work, though.

A general tip with runtime errors: Go into Preferences -> Build Options, and turn on debug mode. That way you get specific line numbers on your runtime errors, which makes them easier to fix. In this case there was only one line in that proc that could have caused a "null.mob" error, but sometime's it's not that clear-cut.
In response to Crispy
Apparently, I managed to delete the client.. -_-

I still recieve an error on the same line but now it is failing to read null.key of M.

I think the error is caused by something else in the coding... src.client.mob=M should work perfectly.

The coding that I posted initially is the only coding used.
In response to Xallius
You didn't delete the client; if you had, you wouldn't be connected to the game any more and you wouldn't get to see the error message. =) Somehow the client has logged into a different mob than src.

M is null? Strange. Try browsing through the savefile and see if it's actually saving correctly. You can write your own savefile viewer fairly easily by looking up ExportText().