I just want a message to be sent to the current logged-in player. I searched and found either:
usr << "Welcome"
or
src << "Welcome"
Which both work as I test 'em but is there any difference between them two?
Thanks
http://www.byond.com/forum/?post=2003116#comment17822051
^Very in-depth explanation of what src and usr are. |
In most cases where src==usr, you should never use usr.
src is the thing that a procedure or proc belongs to. usr is the thing that invoked the action. For example: in obj/Click(), src is the object being clicked, usr is the mob that clicked on the object. obj/Click() in a verb (or proc) invoked as a verb (user clicked on it with their mouse, or typed the command), usr is usually the same as src. mob/verb/hi() in a proc (or verb), src can be whatever object the proc or verb belongs to, while usr is the one that started the chain of actions. mob/verb/call_hi() For the above: locate() lets you select objects by their tag var, I personally set every client's mob's tag var to their key for easy access to mobs. This will call the hi() procedure we defined above, except now other_person is src, while usr is the person who used the call-hi verb. You shouldn't actually do this, but it's an example where they'll be different. |
In many cases the two variables are the same value, but not all and there are some rules to follow when it comes to things.
The first thing to understand is "src" means source, and "usr" means "user". The source is the object that the function (proc/verb) belongs to, the user is what executed that function.
In the case of /mob verbs, usr and src are most often the same thing because the verb is being executed by the mob that it belongs to, but when you get into things like verbs belonging to objects things start changing.
When a player executes an /obj verb, the src variable will be the object and the usr will be the player.
For procs things can get a little complicated, but the rules are still the same, it just depends on how you call the proc, but a good rule of thumb for procs is to avoid "usr" outright, it's unreliable, you should always use "src" to point at the thing holding the proc, while using arguments to determine other values such as who's executing the proc.