obj
objname
Move()
var/d = ..()
spawn()
if(d)
//some code here
return d
Problem description:can anyone explain me what that ..() do? ive seen that in many ocasions but i cant figure out by my own what is it for. thanks =)
Code:
obj Problem description:can anyone explain me what that ..() do? ive seen that in many ocasions but i cant figure out by my own what is it for. thanks =) |
..() is short-hand in DM for calling the parent proc of the current proc, DM uses a tree-based structure for its code, each branch of the tree can have branches splitting from it; these are called children and parents.
obj Now here we have a parent with two children, the parent has a proc defined called 'SomeProc', the children will inherit this proc from the parent, so it doesn't have to be defined again for them. When you call parent.SomeProc() you'll output "Hello!" to the world, when you call child_one.SomeProc() you'll output "Howdy!", but when you call child_two.SomeProc() you'll output "Hola!" AND call the parent's SomeProc() which will result in "Hello!" also being displayed. This works throughout the code-tree and can be nested multiple times (eg: Calling ....() to call the parent of the parent =P) In the case of built-in procs like Move() and the sort, if you're already at the topmost override of the proc and you call ..() you'll execute the 'default action' of that proc, which is mentioned in the DM reference -- for Move() it would be moving the player and calling the various procs associated with that like Enter() and whatnot. If you don't execute the parent when overriding a built-in proc you usually end up with undesired behavior due to the default action never being executed. But in some cases you want to exclude the parent, such as when you want total control over the process without built-in logic coming into play. In the example code you're showing, you basically take the return value of obj.Move(), check it, and return it in objname.Move() -- it's not actually doing anything since if you excluded that code objname.Move() would be the same as obj.Move() and would return the same value as it anyways. But if you're interested in a more efficient and cleaner way of writing functions like that: obj Now you have the '.' variable, which instead of the parent, refers to the child, when used in a proc it refers to the proc itself, and setting it will in turn alter the value that proc returns when it finishes, even if you don't ever 'return' a value. Think of a computer file system, the '.' directory is the current directory and the '..' directory is the directory above it. Hope this helped you understand better :) |
In response to Nadrew
|
|
Thanks man, i really apreciate your atention. Ill take some time to study what youve writted. Thanks :)
|
In response to FKI
|
|
Thanks bro, that was quite helpfull, ill read that guide you mentioned. Thnx :d
|
This may help, the comments are valuable as well.
http://www.byond.com/members/ Ss4toby?command=view_post&post=115842&first_unread=1 A post I made back in 2011 when I first discovered the use of ..(). Kinda sad considering I had been programming on BYOND for 8 years.. |
So, in terms of your code snippet, objname's Move() proc is called, and then var/d = ..() calls /obj/Move() (and returns the result to d).
More information here.