ID:141516
 
Code:
L.spelldelay=1
var/list/J[1]
var/C = 1
var/mob/enemies/M
for(M as mob in oview(5))
if (istype(M,/mob/enemies))
J[C] = M
C++
J.len++
if(J[1]!=null)
MP -= round(14*sqrt(poisonlevel),1)
M = J[1]
missile(/obj/spells/poisonbolt,usr,M)
sleep(get_dist(usr,M))
M.overlays += /obj/spells/poison
var/D = round(4+(poisonlevel/2),1)
while(D>0)
var/damage = round( rand(10*(sqrt(poisonlevel*((Intelligence/100)+1))),13*(sqrt(poisonlevel*((Intelligence/100)+1)))) , 1)
if (M.poiswk>0)
damage = round(damage*(1+(M.poiswk/100)),1)
if (M.poisres>0)
damage -= round(damage*(M.poisres/100),1)
M.HP -= damage
s_damage(M, damage, "green")
sleep(10)
DeadEnemy(M)
D--


Problem description: Whenever i use the spell, and a monster dies, i get a runtime error with anything thats under "while(D>0)" and the runtime error says "runtime error: Cannot read null.poiswk" and its not just the poiswk, i tried taking that out, and it still had the same error but with poisres and so on....
The cause is pretty obvious, and its a symptom of not exactly understanding what you're doing/lists and so not being aware what the effect of your code precisely is. The error means M is set to null at the time the code accessing those vars executes.
In response to Kaioken
Well, what makes no sense, is that that's the ONLY spell i get that error with, the other spells work just fine, and they have the same vars just that they're not the poison vars.
In response to Yamikaiba1236
Every time you sleep() you're naturally not executing statements one after another instantly; there is therefore a space for other functions to execute and for things to happen - which includes any object you may be messing with being potentially deleted. Especially if the current proc can do the deletion.