ID:1728035
 
(See the best response by Neimo.)
Code:
Crossed(A)
if(istype(A,/mob))
var/mob/O=owner
var/mob/D=A
if(O.aff==D.aff)return
D.snared(15*O.tier51,3)
if(istype(A,/obj))
var/obj/T = A
if(T.density)
T.loc=loc


I get the following runtime error:

runtime error: Cannot read null.aff
proc name: Crossed (/obj/staticfield/Crossed)
source file: Copy Ninja Jutsus.dm,84
usr: JonJon (/mob/player)
src: the staticfield (/obj/staticfield)
call stack:

"aff" is a mob/var initialized to 0. I don't know why it's saying it's null. And I'm not certain why I'm getting this error.

Best response
Either O or D is null, that's what the error means.
I don't see how either of them could be null
if(o)
world << "o exists"
else
world << "o does not exist"

See what happens! Add it underneath the variable referencing and above the if() statement.
Oh, obj/var/owner is set to null. What would be a better way to initialize it? owner is set to whoever makes the obj

Also, the results were:

o exists
o exists
o exists
o does not exist
o does not exist
o does not exist
o exists
o exists
The default value of the owner variable doesn't really matter in this case.

obj
Lightning
New(location, caster)
..()
src.loc = location
src.owner = caster

Crossed(A)
if(istype(A, /mob))
var/mob/O = owner
var/mob/D = A
world << "[O] [O.aff], [A] [D] [D.aff]"
if(O.aff == D.aff)
world << "return"
return
D.snared(15 * O.tier51, 3)
if(istype(A,/obj))
var/obj/T = A
if(T.density)
T.loc = loc

mob
verb
CreateLightning()
new/obj/Lightning(src.loc, src)


I tried it with that and it worked fine. Not sure why it's giving you an error.
It's a little confusing why only some of the times O is not set to null. The logic works fine, I just don't know why I'm getting the error
Could you post the code for the entire technique? It would be a lot easier to pinpoint it that way.