ID:854107
 
(See the best response by Nadrew.)
Code:
turf
sand
icon = 'icons/Sand.dmi'
Entered(mob/m)
if(usr)
m.loc = locate("dirt")


Problem description:
when the mob enters the turf, it relocates the mob. the problem is that i would like usr to be only relocated. all other mobs should be ignored. this example is not working as it should. usr always results in null and i don't know why. can't the usr be under the turf code? can someone please explain why usr is null in this case.
Entered(mob/m) isn't only called when mobs enter the turf, you've got to do some more detailed runtime checking for that.

"usr" is generally invalid or unreliable in procs, you're using "m" as you should here, usr isn't meant to be used inside of Enter() or Entered() at all.

You're pretty close as it is, by using the argument to Entered(), so lets expand on that a bit.

Entered(mob/m)
if(ismob(m)) // This is important, it verifies m is actually a mob
m.loc = locate("dirt")


You may also want to add a client check if you only want players to teleport.
could you refer me to where i could learn how to do a client check or better yet, provide a quick how to only let players teleport?
Best response
You could expand the if() statement containing the ismob() check.

if(ismob(m) && m.client)
Every mob has a client variable that only has a value if there is a client connected to it. So just do if(m.client).
thank you to the both of you. i learned a lot once again!

ps. i first learned that usr was invalid when calling a proc like usr.Move but i never knew that usr is also invalid when coded inside of a proc :)
In response to Kalster
You can call a proc with usr all you like. The issue is when you're using usr anywhere but a verb (or some pseudoverbs, like obj/Click()). Basically, in a verb usr is going to be whoever initiated the action, and in most procs usr should be considered unreliable.