ID:170430
Jan 25 2005, 2:44 pm
|
|
I have trouble understanding when you would need to use call. Am I missing something or is it useless?
| |
#2 Jan 25 2005, 3:56 pm
|
|
Having seen call for what seems like the first time, I notice a usr in proc there. Is that ok to do?
| |
DeathAwaitsU wrote:
Having seen call for what seems like the first time, I notice a usr in proc there. Is that ok to do? Unless you're talking about a post in which you saw somebody override call(), which you probably aren't, then it, as always, depends on the context. You see, Death, usr is basically the last player to do something. It works, however, because instead of being a global variable, it's a variable which is passed down from function to function. That's why if Player A presses mob/verb/Attack() and Player B presses it at the same time, Player A's Attack()'s usr will be Player A, while Player B's Attack()'s usr will be Player B. Although it is very often wrong in procs, at times, if the developer knows what (s)he's doing, then it's perfectly fine. usr, as a rule, is always safe in DblClick(), Click(), and Stat() because, for example, the player who Click()ed will always be Click()'s usr. There are other times where it's essential to use both usr and src. For example, in Topic(), the src can be manually defined by the hsrc arument, while usr will always be the hyperlink-clicking player himself! In sum, as long as you know what you're doing, and you truly do mean usr, and not src, then it's perfectly fine to use usr in proc: usr is not intrinsically evil. | |
#4 Jan 25 2005, 7:18 pm (Edited on Jan 25 2005, 7:52 pm)
|
||
I have trouble understanding when you would need to use call. Am I missing something or is it useless? It's for having the equivilant of function pointers like in C/C++. Generally in other languages it's used to set up call back functions for asynchronous function calls or event handlers. So if you're writing a library this type of stuff is good for setting up hooks to allow custom tailored behaviour without the user needing to edit the libraries source code. [Edit] Anyway here's an example of something you could do. Say the standard spawn didn't do everything you wanted it to do since occasionally you want to take back calls or otherwise monitor your call queue. Heres how you could implement your own version.
Not exactly the most trivial example but an example of how to make use of it. | ||
I was talking about the example the reference uses:
I was just wondering if thats correct. | ||
#6 Jan 26 2005, 5:24 pm (Edited on Jan 26 2005, 5:38 pm)
|
|
Thanks everyone, now I understand it
EDIT Wow, I just realized how useful call can be... thank you more | |
DeathAwaitsU wrote:
I was just wondering if thats correct. Your use of call() is correct, but unfortunately, your use of usr wasn't. In that situation, you should have used src.
[edit] I posted the DM Ref entry usr abuse at [link]. [edit*2] Please note that although usr is technically OK in the DM Ref example, its use there is very brittle, because if Proc1() or Proc2() were to be called in the wrong place by the developer, then they would have a large chance of failing miserably. It's only OK because usr is being passed down from the verb, call_proc() into Proc1() or Proc2(). | ||
It isn't useless. If you want to dynamically call a proc or verb, then call() is the way to go. However, in general, the rule of thumb is not to use it unless you need it.