ID:2002476
 
(See the best response by Nadrew.)
I was just introduced to Byond while I am at my friends house. I figured I would give it a shot but I can't find an answer to my question. What is the difference between usr and src? I tried finding it in the help file I looked in the DM reference even searched the forums. I know it is kind of silly but I figured might as well ask.
usr means user
src means source
I hate to be a bother but could you maybe give me kind of an example of when each term should and shouldn't be used. I guess I wasn't very clear with my question I understand what they stand for but what I don't understand is when I should use source over user and for what reason. :-)
Best response
The "user" would be what initiated an action, the "source" would be the owner of said action.

obj
verb
Something()
set src in view(src)
usr << "usr is [usr], and src is [src]"


In this example, if a player uses that verb, "usr" would be the player and "src" would be the object.

In most instances where you'd expect them to be the same thing (procs, Login(), etc...) you should always use "src" because there could always be a niche instance where "usr" and "src" are different values (if a player executes a proc belonging to a different player for instance).

It's pretty standard to assume "usr" to be unreliable in procs, but fairly safe in verbs belonging to mobs, but even in that instance you should probably use src if you're unsure of how you'll be executing the verb.
Thank you Nadrew that was a perfect explanation. :-)
BYOND is pretty verb-driven under the hood, so basically usr is whoever initiated the verb, and src is whatever the proc or verb belongs to.

The usr var is a sort of "hidden" var that gets passed from the verb to whatever other procs it calls. In theory you can use it in many procs, as long as you're sure you know it's correct. In practice it's safer not to.

The reference used to be riddled with things like this:

turf/Entered()
usr << "Hi, you stepped on me."

Entered() is not usr-safe, because it can be called by all kinds of things moving around: monsters, projectiles, etc. It does however take two arguments, the first of which is the thing that entered.

turf/Entered(atom/movable/A)
if(ismob(A))
A << "Hi, you stepped on me."

This is the best way to approach usr safety: If the thing you want to refer to in a proc isn't src, it should be passed as an argument. For instance:

// Here, src is the mob taking damage
mob/proc/TakeDamage(amount, mob/attacker)
hp = max(0, hp-amount)
DeathCheck(attacker)

// src is the mob that might be dying
mob/proc/DeathCheck(mob/attacker)
if(!hp)
attacker.xp += xp_value // whatever I'm worth
attacker.LevelUp()
DropLoot()
// die and respawn (later, if it's a monster)
Respawn()
Thanks Lummox! Good solid information. :-)