ID:169836
 
Last time I asked about Datums and a lot of people helped me out with them. I especially learned a lot from Wizkid and Lummox. But this time I am wondering if you can give me a breif description on the return statements and what they do.
It's what is returned from the proc.

proc/IsSexy(mob/M)
if(M.name == "Ryan Baker")
return 1 //return true
else
return 0 //return false

proc/NameTheSexyOne()
for(var/mob/M in world)
if(IsSexy(M))
return M.name //You can return text also!
mob/verb/Who_Is_Sexy()
world << NameTheSexyOne()


I imagine this is a good example? I know you can return: numbers, text, and list.

-Ryan
In response to Ryne Rekab
Hey man thanks. <insert happy face here>
In response to DragonMasterGod
DragonMasterGod wrote:
<insert happy face here>

:D

-Ryan
In response to Ryne Rekab
Also. just put "return" with nothing after it. it returns null automaticly
I'll try explaining it with a snippet:

proc/return_foo()
return "foo"

mob/verb/learn_about_return()
//Outputs "foo"
src << return_foo()


Any proc that returns something is called a function.

You already use many functions without even knowing it! For example, input() and alert() are both functions that return the value which the player picked.

Technically speaking, any proc in DM is actually a function. If return is not called manually in a proc, then that proc will return a value of "." (without the quotes). By default, . is equal to null.

When return is called, the proc immediately ends, returning the specified value. Therefore, we can do things like the following:

atom/proc/get_density()
if(src.density)
return 1
return 0


There, the else isn't needed because if the atom's density is equal to 1, then the proc will end right then and there, returning 1.

Of course, the above get_density() proc can be done much more efficiently like so:

atom/proc/get_density()
return src.density


Any sort of value can be returned, including objects and lists (ie: view())!

Often, return is actually used under a conditional in order to end a proc before it reaches the last line:

mob/verb/land()
//You can't land if you're already on the ground!
if(!src.density)
return
src.density = 0
src << "You come down from the skies and land back on the solid earth."
In response to Wizkidd0123
Hey Wizkid thanks man.
In response to Ryne Rekab
Roflmao, you inserted the smiling face.
In response to Itachi1
Thanks man.
In response to DragonMasterGod
No way...

-Ryan