ID:162065
Feb 29 2008, 12:50 am
|
|
When programming a game, which is better, using [src] or [usr] for Stats, Inventory and whatnot. Do they mean the same thing, is one better then the other when you allow a player to have more then character, somebody inform me please.
|
If your using it in a verb or mob/Stat you dont need either if your referring to the person using it, you could just put:
mob/verb/Train() You dont need src or usr for those such of things, it'd be a waste of typing. And src and usr arent the same thing anyway, they each have their own places. If you dont put src. the compiler automatically assumes its src., so theres really no point using it at all in most cases. You can code a whole game without using even 1 src. in your code. In fact my game is standing proof of that, Dragonball Finale doesnt have even 1 src. anywhere in its code. I cant think of one situation where its necessary to use src., "src" on the other hand is a different story. |
usr refers to the object that started the call stack.
For example: proc/force_verb(mob/M) If you called force_verb() on another mob, "usr" will be the person who called force_verb, not the mob who actually owns the verby verb (IE, not M). src refers to the object that owns the verb. Like in the above example: src was the mob, while usr was the caller. |
In response to Dragonn
|
|
How would you do this without src?
if(M == src)
|
Jamora1124 wrote:
When programming a game, which is better, using [src] or [usr] for Stats, Inventory and whatnot. Do they mean the same thing, is one better then the other when you allow a player to have more then character, somebody inform me please. src and usr are definitely not the same thing. The distinction between them is a little confusing for new users, but it basically boils down to this:
|
In response to Dragonn
|
|
Dragonn wrote:
If you dont put src. the compiler automatically assumes its src., so theres really no point using it at all in most cases. Right, src. is pointless and shouldn't be used because if you don't write it the compiler uses it anyway, (when possible). :P Seriously though, you should tend to include the full syntax because it makes the code easier to understand, and not only in terms of simplicity - the shortcut is more for advanced people to use, since it's more vague (I prefer to write it out fully myself). The full syntax distinguishes the variable from a local or global one, and of course that it belongs to the source object, which all make it easier to newbies to get acquainted with the language. And of course you have to write it fully if there's a global or local variable with the same name as one of src's vars, which can surprisingly be considerably common in certain procs. To expand on what others have said, 'src' and 'usr' aren't always the same, but when they are, it's more useful to use 'src'. |
In response to Traztx
|
|
Oops, Dragonn I didn't realize you said without using "src." but I took the "." as the end of your sentence. I see now that you mean and agree.
I'm behind a proxy so I can't test this out, but I wonder what the following does: var My guess is that output is "something==c, src.something=b" because the local something overrides the object's something as well as the global something, but the explicit reference to src clarifies it. And of course, there isn't a vital reason to name variables like that, so I still agree "src." is unnecessary. |
For the sanity of all newbies, src is better. People should leave usr alone unless a player is accessing verbs or procs belonging to another object, such as obj/verb/Get() or obj/Click(), in which case src is the object and usr is the player.
Other uses for usr exist, but they are few and far between and should really only be done by people who know what they're doing! |
In response to Foomer
|
|
Foomer wrote:
For the sanity of all newbies, src is better. People should leave usr alone unless a player is accessing verbs or procs belonging to another object, such as obj/verb/Get() or obj/Click(), in which case src is the object and usr is the player. I don't advocate giving this kind of simplified advice that has just lead to people making the same mistakes over and over again. People should know the fully story behind src and usr. This kind of reminds me about that fiery argument between the usage of . and : that in the end showed people were horribly misguided about their merits. |
This will help you out:
http://www.byond.com/members/ DreamMakers?command=view_post&post=35932