ID:136403
 
What is the difference between
. = ..()
and
..()
for returning the parent proc in a proc?

Also, what is the actual function of these two? Does ..() simply return the proc of the parent_type, or will it look for other procs on the same type level?


~Polatrite~ Hopefully it made sense.
Polatrite wrote:
What is the difference between
. = ..()
and
..()
for returning the parent proc in a proc?

Also, what is the actual function of these two? Does ..() simply return the proc of the parent_type, or will it look for other procs on the same type level?

All DM functions implicitly return a value. That value is stored in the '.' variable This is null by default, but you can override it to return something else. These two functions are therefore identical:
proc/one()
. = 1
proc/two()
return 1


So . is mainly useful as a shorthand to assign a return value ahead of time.

..() is a proc referring to the parent's version of the current function. So doing ..() will call the parent function. Doing . = ..() will call the parent function and set the return value of the current function to that of the call. Just think of it as two steps:
  var/ret = ..() // call parent function
. = ret // this is what we'll return

If the function ends there, this is just the same as:
    
return ..()
They are sort of apples and oranges. They just happen to be used together in some examples and both have the '.' character. The ..() operator performs the parent proc. The . operator sets the return value.