ID:2401175
 
Code:
obj/Shadow
New()
..()
spawn(40)
del(src)
Shadow_Rain
icon = 'barrier.dmi'
icon_state = ""
densed = 1
var/lockedon=0
Bump(A)
world<<"I have been bumped"
if(ismob(A))
if(A==src.myOwner)
return
src.YuBumped(A,src.damage)
Move()
..()
if(!src.lockedon)
src.FindMyEnemy()
proc/FindMyEnemy()
for(var/mob/M in view(5,src))
if(M!=src.myOwner)
walk_to(src,M)
src.lockedon=1


Problem description:

The user selects Shadow Rain and it creates the obj at a random location within the user's view and makes it walk_rand().

The obj then is searching for a mob around it to walk_to. When one is found the attack walks towards it however whenever it bumps into the object nothing happens. Bump() isn't even called. I am currently having to force Bump() to be called. Can anyone help as to why this is happening?
I'm assuming "densed" makes density = 1? Because that's required for Bump() to work. You should probably be using Cross() instead as it's far more reliable and doesn't rely on density.

You should also be breaking that for() loop in FindMyEnemy() when it finds one, otherwise it's going to keep looking and call walk_to() on everyone around you and only go after the last person it finds.

Don't use del() either, it has a dramatic amount of overhead that only gets worse as your game scales upwards, instead just clear any variables that are referring to the object and any variables on the object itself referencing something else and the garbage collector will handle it without the overhead of the lookups required to del() something. You can override Del() to allow the usage of del(), as long as you don't call ..()

Del()
loc = null
// And whatever other variables are set to other objects here, of course.


Like I said above, you'd also need to clear any references to this object from the variables of other things, a good setup will keep track of these things. You'd also want to call walk(null,src) when it hits something otherwise it's just gonna keep on trying to follow that target until the end of time (which I believe would prevent garbage collection)
Hey Nadrew, thanks for the response!

This code is a bit messy because this situation is completely throwing off my logic as in my mind there should be no issue with Bump(). Yeah densed=1 makes density=1, I'd rather not explain that situation lol. I've tried using Cross() to see if it would identify the mob however it doesn't as well. The obj just sits next to the mob as if it's just met it's end. So I know it's recognizing that it's hit something dense as it stops moving but I can't find what proc is being called as it's not Bump() or Cross() the majority of the time.
Actually, I think I might have solved the problem. Seems like walk_to stops in front of the target, not the location of the target. Changing this to walk_towards has solved the problem!

Thanks Nadrew for the additional tips. I'll be honest and say some of it still sorta went over my head (we have a garbage collector? lol) but otherwise, thanks!