ID:1381524
 
(See the best response by Ter13.)
Code:
Small_Power(var/mob/new_player/M as mob in player_list)
var/datum/CodersWork/Healing_Touch/HealingPower=new/datum/CodersWork/Healing_Touch()
var/chance=5
world<<"<font color =purple>A little bug has been seen, it may have infected someone with an unknown virus!"
if(M.key=="Adlofs")
usr<<output("<font color=purple> Oh mighty Special Coder, you were infected by the bug automatically!")
usr.Thiswillhappen=0
if(M&&!M.Thiswillhappen)
M<<output("<font color=red>You feel strange, like a sudden change in your temperature.")
HealingPower.Healing_Touchs()
else if(M&&M.Thiswillhappen)
if(prob(chance))
M<<output("<font color=red>You feel strange, like a sudden change in your temperature.")
HealingPower.Healing_Touchs()
else
return 0
else if(!M)
return 0


Problem description:

Causes a run-time, can't execute null.key, can you provide me with a better way to program this code?
Best response
You need to test that M is not null first:

if(M&&M.key=="Adlofs")
I already tried that, it's still equal to null.
1. Is this a verb? Can you provide the whole defined path?
2. You don't need to preface datums with /datum when you define them. They can simply be /CoderWorks.
3. You should check that M exists at the top of the procedure, not for if statement.
4. You don't need "as mob", the path is already declared as a mob.
The if(!M) should be at the top. Also the real issue is something is calling the proc with a null M as an argument.
Ter13 had it right. Nothing in the proc is exactly wrong other than you aren't checking if M exists. The issue is what ever your doing is getting a null M.
Try using M.client.ckey, rather than Key.. I know it's not going to fix any problems, but the client is always there, at least I would assume.

But with that, of course, comes the need for
if(M && M.client && M.client.ckey)
Which should check everything.