ID:152972
 
I have read the developer faq on this and the dm guide,I still do not understand what they are for.
Broly103 wrote:
I have read the developer faq on this and the dm guide,I still do not understand what they are for.

Every procedure has a variable named '.'. Simply, it is the default return value the procedure would have.

proc/blah()
. = "blah"


would be the same as

proc/blah()
return "blah"


So what is good about it? The difference is that doing . = ..() would let you do the default stuff for the proc and still continue if you want to return it.

mob/Move()
return ..()
src << "You moved!"


This would not say "You moved!" to the mob, because the proc would have already stopped.

mob/Move()
. = ..()
src << "You moved!"


This, however, would output "You moved!"

~~> Dragon Lord
"..()" means "call the parent type's version."
mob  //this is the parent type
proc/MyProc()
src<<"1"
sub_type //this is the child type
MyProc()
src<<"2"

With that, if you were of type /mob you would see "1" output when your MyProc function was called. If you were of type /mob/sub_type, however, you would see "2".

It is also important to note that built-in functions for the root type they were defined for will do their normal action when you use ..() Therefor, also there is not actually an /atom/movable/Login, you can still use ..() in /mob/Login and it will do its otherwise normal action.

With the following, type /mob/sub_type will see both "1" and "2".
mob
proc/MyProc() //parent type's function
src<<"1"
sub_type
MyProc() //child type's altered version
..() //calls parent type's version, which will output "1"
src<<"2"

As for return values, that brings a value over to the spot where the function was called.
mob
proc
MyProc1()
var/N=MyProc2() //N=3
MyProc2()
return 3

And, as Unknown Person said, "." is a variable that contains a return value. If the function ends without return being called, it will automatically return whatever "." equals.
mob
proc
MyProc1()
.=3 //when this function is finished, it will return 3
MyProc2()
.=2
return 1
/*This function sets the return value, but it decides to
use the return statement instead of let it return the
return value, therefor it will return 1*/

mob  //mob's parent is /atom/movable
Move() //atom/movable returns 1 on a successful move or 0 if movement failed
.=..()
/*The above line runs the parent type's (/atom/movable)
version of Move, which will return 1 on a success and 0 on
a failure. It then sets the return value to equal that 1 or 0
so that this function will now return the same thing. You can
also use the return value afterword yourself to check and see
whether it succeeded or failed.*/

if(.) //if movement had succeeded
src<<"Your move was successful."
else
src<<"Your move was successful."

We can use this in many ways. For my example I will bring up random battles brought up during movement for your typical RPG. You probably don't want a battle to occur if the player tried to walk into a wall and the movement failed.
mob
Move()
.=..()
if(!.) //if movement failed, most likely due to an obstacle
return . //I probably could have just done return 0, either works
//At this point, if that return statement was executed due\
to an obstacle, nothing after it happens as the function is finished

if(prob(10)) //10% probability for a random battle
battle() //battle would probably be made into a global function
Those are fabulously clear answers, thanks to both of you on clearing that up in my mind :)