mob/npc/var/list/threats
mob/npc/var/mob/target
mob/npc/proc
add_threat(mob/a)
if(!src.threats)
src.threats = new
else
if(a in src.threats)
return 0 //threat already recognized
src.threats += a
src.threats[a] = 1000
return 1 //successfully recognized new threat
remove_threat(mob/a)
for(vat/mob/m in src.threats)
if(m == a) src.threats -= m
if(!src.threats.len) //error line: "cannot modify null.len"
src.threats = null
moving()
while(src.target)
if(src.target in oview(src.aggro,src))
step_to(src,src.target)
sleep(src.move_delay)
else
src.remove_target(src.target)
if(src.threats) //if there are still threats around
src.target = src.threats[1]
else src.spawning() //proc to return to its spawn location
Problem description:
Cannot modify null.len is the runtime error produced when I move outside the NPC's "aggro range" and it tries to remove me as a target. The error line is commented in the above snippets. I do not understand why the list would be null when it is clearly initialized and added to upon the addition of a threat. Maybe it has to do with how I sort the threats list when I add new threats to it? I use merge sort to organize the list from highest to lowest threat.