ID:146867
 
I'm getting the 'Cannot modify null.var. However, the output I'm getting makes no sense what-so-ever to me.

LoadPlayer(mob/M)
var/
savefile/S = new("players/[copytext(M.client.ckey, 1, 1)]/[M.client.ckey].sav")
mob/live/player/P
temp_x = 0
temp_y = 0
temp_z = 0

S["player"] >> P
S["x"] >> temp_x
S["y"] >> temp_y
S["z"] >> temp_z
P.loc = locate(temp_x, temp_y, temp_z)
if(M.client == null)
world << "GAH!"
M.client.KeyHandler = null
M.client.mob = P
sleep(1)
del(M)

The LoadPlayer proc is defined under /mob/live/loginMob/proc. The following is the runtime error:
runtime error: Cannot modify null.KeyHandler.
proc name: LoadPlayer (/mob/live/loginMob/proc/LoadPlayer)
usr: Nova2000 (/mob/live/loginMob)
src: Nova2000 (/mob/live/loginMob)
call stack:
Nova2000 (/mob/live/loginMob): LoadPlayer(Nova2000 (/mob/live/loginMob))
Nova2000 (/mob/live/loginMob): MainMenu(Nova2000 (/mob/live/loginMob))
Nova2000 (/mob/live/loginMob): Login()
Nova2000 logs in.
GAH!

The last two lines are world << "" lines. What gets me is that GAH is occurring _after_ the "x logs in" part. The "x logs in" string occurs in /mob/live/player/Login(), and since the client is connected to that _after_ "GAH" /should/ be written..., why is "GAH" coming out the tube second?

But more importantly: What on earth causes the 'can't modify null.KeyHandler' (/client/var/proc/KeyHandler) error? As has been shown by the runtime error, M is perfectly valid, and points to me. I am not doing anything radical like logging off, so why should I become null?

Once again, I'm baffled. Thanks for any help in advance.
M is perfectly valid, but that "GAH" line shows you that M.client is not. M.client is null, therefore you can't access its non-existing variables.

Does the P mob have its ckey or key variables set to your key? If so, BYOND automatically logs you in to that mob, and out from your current one.
In response to Jon88 (#1)
Jon88 wrote:
Does the P mob have its ckey or key variables set to your key? If so, BYOND automatically logs you in to that mob, and out from your current one.

I guess that would cause that, if ckey isn't a temp var. I assume ckey is in the savefile, as I simply do a savefile["player"] << my_player's_mob --- which should save the ckey.

I'm gonna go nutty over the weird ways Byond makes sense. I've changed the code to adapt for that... and it works. That would also explain the odd appearance order of the messages.

Thanks a lot for your help, problem solved!
First of all, in this situation, there's no reason to use mob/M. Instead, you can just use src.

Also, although it really isn't too important, var doesn't need the trailing slash:
var
thing=5


Finally, as you can see from the DM Ref entry for tmp, atom.x, atom.y, and atom.z are all temporary vars.
In response to Wizkidd0123 (#3)
Wizkidd0123 wrote:
Finally, as you can see from the DM Ref entry for tmp, atom.x, atom.y, and atom.z are all temporary vars.

Exactly! That's why he's saving them manually.