ID:1759352
 
(See the best response by Mar big.)
Code:
mob
proc
Charge()
var/obj/X = new/obj/Projectile
X.layer = 6
usr.overlays+=X
var/N = 3
lap
for(var/mob/M in get_step(usr,usr.dir))
if(M!=usr)
M.Damage()
N-=1
sleep(3)
if(N>0)
goto lap
else
goto final
step(usr,usr.dir)
N-=1
sleep(3)
if(N>0)
goto lap
else
sleep(5)
usr.overlays-=X


So Im having an issue with some code that seems to work fine in another area of the game, but for some reason its not working on this one proc. basically the premise of the code is to make an overlay appear ontop of the user, have them rush forward in the direction their facing, and do damage to anyone standing in their way. The only issue Im having is that the overlay has decided it doesnt want to go away, I have tried everything I can think of, and it seems to be going well to the line itself, so i cant think that theres much else of a solution then to ask byond.

Best response
You should not be using usr in the proc. Also you should be using a while loop instead of goto.
mob
proc
charge()
var/obj/projectile/x = new/obj/projectille
x.layer = 6; src.overlays += x
var/n = 3
while(n)
for(var/mob/m in get_step(src,src.dir))
if(m != src)
m.Damage()
n--
sleep(3)
sleep(5)
src.overlays -= x

I also recommend using the image proc for overlays instead of creating objects.
//The first parameter is an icon, and the second parameter is an icon state.
src.overlays += image('pants.dmi',"red")
ill try the image proc, but i dont think it will work, as the image im trying to apply has a variable icon and state depending on what ability is used.
so, ill be honest, i feel super stupid now.

so, it wasnt working, and i did some checking up on the code, and it was deleting the new object before it could get to the end of the proc, therefore having nothing to remove from the overlays, after some more debugging with that i managed to get it working, thank you for the help though