ID:175933
 
For some reason when loading i get a runtime error. Please help me fix the runtime error, Here's all my char handling coding:
mob
proc
CreateChar(mob/M)
Name
var/char_name = input("Please name your character.","Name") as null|text
if(char_name == null)
goto Name
var/Type = input("What type of Chao would you like to be?") in list("test","tester"
if(Type == "test")
usr.icon = 'mob.dmi'
goto Start
Start
usr.name = char_name
usr.loc = locate(1,1,1) // spawn the character to 1,1 on map #1
usr.sight = 0 // make it so the character can see
usr.Save() // Auto-Save the new char for just in case game crashes.

SaveChar(mob/M as mob) //The proc that saves your character.
var/savefile/F = new("players/[src.key].sav") // define the save file and create it
F["N=name"] << name // Outputs the characters name into the savefile list
F["X"] << src.x // Outputs the char's X coordinate into the list
F["Y"] << src.y // Outputs the char's Y coordinate into the list
F["Z"] << src.z // Outputs the char's Z coordinate into the list
F["Mob"] << usr.client.mob // Outputs ALL of the character (var's, etc) into the list

Load(mob/M as mob) // The load character proc
var/savefile/F = new("players/[src.key].sav") // define the location of the save file
var/X // Defines a temporary X variable
var/Y // Defines a temporary Y variable
var/Z // Defines a temporary Z variable
var/mob/newmob = new() // Initialize a new mob
F["name"] >> name// Load the name from the list into the character's name
F["X"] >> X // Load the X variable from the savefile to the temporary X variable
F["Y"] >> Y // Load the Y variable from the savefile to the temporary Y variable
F["Z"] >> Z // Load the Z variable from the savefile to the temporary Z variable
F["Mob"] >> newmob // Load all the mob data into the initialized mob
newmob.loc = locate(X,Y,Z) // Move the initialized mob to the last saved location
src.client.mob = newmob // change the clients mob to the initialized mob
del(src) // delete the old mob from memory (not the initialized mob)
Knowing what the runtime error is would help.
In response to Garthor
runtime error: Cannot read null.mob
proc name: SaveChar (/mob/proc/SaveChar)
usr: (/mob)
src: (/mob)
call stack:
(/mob): SaveChar(null)
(/mob): Save()
(/mob): Logout()
(/mob): Load(null)
Load (7,9,5) (/turf/Load): Click(Load (7,9,5) (/turf/Load))
runtime error: Cannot modify null.mob.
proc name: Load (/mob/proc/Load)
usr: (/mob)
src: (/mob)
call stack:
(/mob): Load(null)
Load (7,9,5) (/turf/Load): Click(Load (7,9,5) (/turf/Load))

Even though this happens it still loads the last XYZ and name
In response to Koolguy900095
Okay, first, the runtime errors. Your problem is that the client is null. This is probably a result of you using usr. Don't use usr in any of these procs. Change it all to src. In the input() procs, add src as an argument before the other arguments. Your other problem is that you're using goto. Why oh why are you using goto? In the first instance, just calling the proc again (and returning the current one) will work just fine. In the second instance, it's totally useless. There is absolutely NO need for a goto right there. Fix those two problems.
You have usr a ridiculous number of places in here. These are all procs; you should be using src.

Anyway, "cannot read null.var" errors have a certain duh factor, meaning that it should have been obvious:
src.client.mob = newmob
It can't read null.mob, so src.client is obviously the null.

The reason src.client is null is that once you loaded the data into newmob, it also loaded the key that was saved with it. As soon as newmob.key was set, newmob took over your client. src is the old mob, so src.client became null. This line can just be deleted without a problem.

[EDIT]
Do not use goto here. Look up while() in the reference.

Lummox JR

In response to Garthor
Garthor wrote:
Okay, first, the runtime errors. Your problem is that the client is null. This is probably a result of you using usr. Don't use usr in any of these procs. Change it all to src. In the input() procs, add src as an argument before the other arguments. Your other problem is that you're using goto. Why oh why are you using goto? In the first instance, just calling the proc again (and returning the current one) will work just fine. In the second instance, it's totally useless. There is absolutely NO need for a goto right there. Fix those two problems.

Egads, I didn't even notice the goto. I was just focusing on the error itself. But the goto has to go.

Lummox JR
Now for some reason i get an error during logout when it saves. Coding:

mob
Logout()
Save()


error:

runtime error: Cannot read null.mob
proc name: SaveChar (/mob/proc/SaveChar)
usr: Koolguy900095 (/mob)
src: Koolguy900095 (/mob)
call stack:
Koolguy900095 (/mob): SaveChar(null)
Koolguy900095 (/mob): Save()
Koolguy900095 (/mob): Logout()

Yes the error is another null...but if i save anytime besides logout i dont get this error