ID:172121
 
Okay I have a monster system, and I need the monster to be located whenever I am moved, so heres the problem, it doesnt always work. Heres my code
                            if(usr.monsterfollow != null)
usr.monsterfollow.Move(usr.loc)

this is only part, but its what you need. Now, Ive tried loc = locate(usr.loc) as well, but the same problem. Please help!
First. You can just write if(usr.monsterfollow) at the start since an if() checks to see if something is TRUE (not null) or FALSE (null).

Second. You can directly edit the usr.monsterfollow's loc var and set it to usr.loc. So usr.monsterfollow.loc = usr.loc will do it.


Third. Make sure that you're using usr correctly. A simple rule of thumb is if you can pass the value on or use src, then you shouldn't use usr.
In response to DarkView
i cant use src because its turfs, but ill check it out, reply back in a min...
In response to Metroid
You're using Enter() or Entered() right? They have a value passed on to them.
turf
Entered(var/atom/A)
if(istype(A,/mob))
var/mob/M = A
if(M.monsterfollow)
M.monsterfollow.loc = M.loc



A is anything that's successfully entered the turf. Remember, not just mobs can move, objs can as well. So we have to check to see if A is a mob.
Then after finding out it's a mob, we throw it in a new mob type var called M. You can get away without doing this, but it makes it more readable.
Then we do what you've done already.