# procs

Source: https://ref.dm-lang.org/proc/

Procs may be derived from /proc. These procs are "global", in that they can be called anywhere in the code.

```dm
proc/poof()
    world << "POOF!"
```

The proc `poof()` may now be called anywhere in the code.

Procs may also be attached to objects by defining them under the appropriate `object/proc` subnode. Currently DM allows procs to be defined or overridden for `/mob`, `/obj`, `/turf`, `/area`, `world`, and `/client`, as well as for [datum objects](https://ref.dm-lang.org/datum/index.md) derived from `/`. Predefined procs are discussed under the "procs" entry for the object type.

```dm
mob/proc/poof()
    world << "POOF!"
```

This can be called by a mob var M, using `M.poof()`.

## Return types

It is possible to define what type of value a proc is expected to return, by following its definition with an `as` clause. This can be a type path, such as `as /mob/player`, or a more intrinsic type like `as num` or `as list`.

```dm
mob/monster
    var/mob/player/target

    proc/GetTarget() as /mob/player
        if(!target)
            // find a /mob/player in view
            target = locate() in view(src)
        return target
```

Currently the only purpose for using the `as` clause is for situations where the compiler needs to infer the type of an expression. Mainly this applies to the [.](https://ref.dm-lang.org/operator/dot.md) and [?.](https://ref.dm-lang.org/operator/querydot.md) operators in an expression such as `GetTarget()?.Attack(src)`. Giving `GetTarget()` a return type allows the compiler to check if `Attack()` is a valid proc for `/mob/player`. Otherwise, the `.` and `?.` operators act like `:` and `?:`, respectively; the compiler won't do any checking to see if `Attack()` is valid.

### See also
- [vars (procs)](https://ref.dm-lang.org/proc/var/index.md)
- [arguments (proc)](https://ref.dm-lang.org/proc/arguments/index.md)
- [procs (area)](https://ref.dm-lang.org/area/proc.md)
- [procs (mob)](https://ref.dm-lang.org/mob/proc/index.md)
- [procs (obj)](https://ref.dm-lang.org/obj/proc.md)
- [procs (turf)](https://ref.dm-lang.org/turf/proc.md)

## Pages

- [abs proc](https://ref.dm-lang.org/proc/abs.md)
- [addtext proc](https://ref.dm-lang.org/proc/addtext.md)
- [alert proc](https://ref.dm-lang.org/proc/alert.md)
- [alist proc](https://ref.dm-lang.org/proc/alist.md)
- [animate proc](https://ref.dm-lang.org/proc/animate.md)
- [arccos proc](https://ref.dm-lang.org/proc/arccos.md)
- [arcsin proc](https://ref.dm-lang.org/proc/arcsin.md)
- [arctan proc](https://ref.dm-lang.org/proc/arctan.md)
- [arglist proc](https://ref.dm-lang.org/proc/arglist.md)
- [arguments (proc)](https://ref.dm-lang.org/proc/arguments/index.md)
- [ascii2text proc](https://ref.dm-lang.org/proc/ascii2text.md)
- [ASSERT proc](https://ref.dm-lang.org/proc/ASSERT.md)
- [astype proc](https://ref.dm-lang.org/proc/astype.md)
- [block proc](https://ref.dm-lang.org/proc/block.md)
- [bound_pixloc proc](https://ref.dm-lang.org/proc/bound_pixloc.md)
- [bounds proc](https://ref.dm-lang.org/proc/bounds.md)
- [bounds_dist proc](https://ref.dm-lang.org/proc/bounds_dist.md)
- [break statement](https://ref.dm-lang.org/proc/break.md)
- [browse proc](https://ref.dm-lang.org/proc/browse.md)
- [browse_rsc proc](https://ref.dm-lang.org/proc/browse_rsc.md)
- [call proc](https://ref.dm-lang.org/proc/call.md)
- [call_ext proc](https://ref.dm-lang.org/proc/call_ext.md)
- [ceil proc](https://ref.dm-lang.org/proc/ceil.md)
- [ckey proc](https://ref.dm-lang.org/proc/ckey.md)
- [ckeyEx proc](https://ref.dm-lang.org/proc/ckeyEx.md)
- [clamp proc](https://ref.dm-lang.org/proc/clamp.md)
- [cmptext proc](https://ref.dm-lang.org/proc/cmptext.md)
- [cmptextEx proc](https://ref.dm-lang.org/proc/cmptextEx.md)
- [continue statement](https://ref.dm-lang.org/proc/continue.md)
- [copytext proc](https://ref.dm-lang.org/proc/copytext.md)
- [cos proc](https://ref.dm-lang.org/proc/cos.md)
- [CRASH proc](https://ref.dm-lang.org/proc/CRASH.md)
- [del proc](https://ref.dm-lang.org/proc/del.md)
- [do proc](https://ref.dm-lang.org/proc/do.md)
- [. proc](https://ref.dm-lang.org/proc/dot.md)
- [.. proc](https://ref.dm-lang.org/proc/dotdot.md)
- [EXCEPTION proc](https://ref.dm-lang.org/proc/EXCEPTION.md)
- [fcopy proc](https://ref.dm-lang.org/proc/fcopy.md)
- [fcopy_rsc proc](https://ref.dm-lang.org/proc/fcopy_rsc.md)
- [fdel proc](https://ref.dm-lang.org/proc/fdel.md)
- [fexists proc](https://ref.dm-lang.org/proc/fexists.md)
- [file proc](https://ref.dm-lang.org/proc/file.md)
- [file2text proc](https://ref.dm-lang.org/proc/file2text.md)
- [filter proc](https://ref.dm-lang.org/proc/filter.md)
- [findlasttext proc](https://ref.dm-lang.org/proc/findlasttext.md)
- [findlasttextEx proc](https://ref.dm-lang.org/proc/findlasttextEx.md)
- [findtext proc](https://ref.dm-lang.org/proc/findtext.md)
- [findtextEx proc](https://ref.dm-lang.org/proc/findtextEx.md)
- [flick proc](https://ref.dm-lang.org/proc/flick.md)
- [flist proc](https://ref.dm-lang.org/proc/flist.md)
- [floor proc](https://ref.dm-lang.org/proc/floor.md)
- [for proc](https://ref.dm-lang.org/proc/for/index.md)
- [fract proc](https://ref.dm-lang.org/proc/fract.md)
- [ftime proc](https://ref.dm-lang.org/proc/ftime.md)
- [ftp proc](https://ref.dm-lang.org/proc/ftp.md)
- [generator proc](https://ref.dm-lang.org/proc/generator.md)
- [get_dir proc](https://ref.dm-lang.org/proc/get_dir.md)
- [get_dist proc](https://ref.dm-lang.org/proc/get_dist.md)
- [get_step proc](https://ref.dm-lang.org/proc/get_step.md)
- [get_step_away proc](https://ref.dm-lang.org/proc/get_step_away.md)
- [get_step_rand proc](https://ref.dm-lang.org/proc/get_step_rand.md)
- [get_step_to proc](https://ref.dm-lang.org/proc/get_step_to.md)
- [get_step_towards proc](https://ref.dm-lang.org/proc/get_step_towards.md)
- [get_steps_to proc](https://ref.dm-lang.org/proc/get_steps_to.md)
- [goto proc](https://ref.dm-lang.org/proc/goto.md)
- [gradient proc](https://ref.dm-lang.org/proc/gradient.md)
- [hascall proc](https://ref.dm-lang.org/proc/hascall.md)
- [hearers](https://ref.dm-lang.org/proc/hearers.md)
- [html_decode proc](https://ref.dm-lang.org/proc/html_decode.md)
- [html_encode proc](https://ref.dm-lang.org/proc/html_encode.md)
- [icon proc](https://ref.dm-lang.org/proc/icon.md)
- [icon_states proc](https://ref.dm-lang.org/proc/icon_states.md)
- [if proc](https://ref.dm-lang.org/proc/if.md)
- [image proc](https://ref.dm-lang.org/proc/image.md)
- [initial proc](https://ref.dm-lang.org/proc/initial.md)
- [input proc](https://ref.dm-lang.org/proc/input.md)
- [isarea proc](https://ref.dm-lang.org/proc/isarea.md)
- [isfile proc](https://ref.dm-lang.org/proc/isfile.md)
- [isicon proc](https://ref.dm-lang.org/proc/isicon.md)
- [isinf proc](https://ref.dm-lang.org/proc/isinf.md)
- [islist proc](https://ref.dm-lang.org/proc/islist.md)
- [isloc proc](https://ref.dm-lang.org/proc/isloc.md)
- [ismob proc](https://ref.dm-lang.org/proc/ismob.md)
- [ismovable proc](https://ref.dm-lang.org/proc/ismovable.md)
- [isnan proc](https://ref.dm-lang.org/proc/isnan.md)
- [isnull proc](https://ref.dm-lang.org/proc/isnull.md)
- [isnum proc](https://ref.dm-lang.org/proc/isnum.md)
- [isobj proc](https://ref.dm-lang.org/proc/isobj.md)
- [ispath proc](https://ref.dm-lang.org/proc/ispath.md)
- [ispointer proc](https://ref.dm-lang.org/proc/ispointer.md)
- [issaved proc](https://ref.dm-lang.org/proc/issaved.md)
- [istext proc](https://ref.dm-lang.org/proc/istext.md)
- [isturf proc](https://ref.dm-lang.org/proc/isturf.md)
- [istype proc](https://ref.dm-lang.org/proc/istype.md)
- [jointext proc](https://ref.dm-lang.org/proc/jointext.md)
- [json_decode proc](https://ref.dm-lang.org/proc/json_decode.md)
- [json_encode proc](https://ref.dm-lang.org/proc/json_encode.md)
- [length proc](https://ref.dm-lang.org/proc/length.md)
- [lentext proc](https://ref.dm-lang.org/proc/lentext.md)
- [lerp proc](https://ref.dm-lang.org/proc/lerp.md)
- [link proc](https://ref.dm-lang.org/proc/link.md)
- [list proc](https://ref.dm-lang.org/proc/list.md)
- [list2params proc](https://ref.dm-lang.org/proc/list2params.md)
- [load_ext proc](https://ref.dm-lang.org/proc/load_ext.md)
- [load_resource proc](https://ref.dm-lang.org/proc/load_resource.md)
- [locate proc](https://ref.dm-lang.org/proc/locate.md)
- [log proc](https://ref.dm-lang.org/proc/log.md)
- [lowertext proc](https://ref.dm-lang.org/proc/lowertext.md)
- [matrix proc](https://ref.dm-lang.org/proc/matrix.md)
- [max proc](https://ref.dm-lang.org/proc/max.md)
- [md5 proc](https://ref.dm-lang.org/proc/md5.md)
- [min proc](https://ref.dm-lang.org/proc/min.md)
- [missile proc](https://ref.dm-lang.org/proc/missile.md)
- [nameof proc](https://ref.dm-lang.org/proc/nameof.md)
- [new proc](https://ref.dm-lang.org/proc/new.md)
- [newlist proc](https://ref.dm-lang.org/proc/newlist.md)
- [noise_hash proc](https://ref.dm-lang.org/proc/noise_hash.md)
- [nonspantext proc](https://ref.dm-lang.org/proc/nonspantext.md)
- [num2text proc](https://ref.dm-lang.org/proc/num2text.md)
- [obounds proc](https://ref.dm-lang.org/proc/obounds.md)
- [ohearers](https://ref.dm-lang.org/proc/ohearers.md)
- [orange proc](https://ref.dm-lang.org/proc/orange.md)
- [output proc](https://ref.dm-lang.org/proc/output.md)
- [oview proc](https://ref.dm-lang.org/proc/oview.md)
- [oviewers](https://ref.dm-lang.org/proc/oviewers.md)
- [params2list proc](https://ref.dm-lang.org/proc/params2list.md)
- [pick proc](https://ref.dm-lang.org/proc/pick.md)
- [pixloc proc](https://ref.dm-lang.org/proc/pixloc.md)
- [prob proc](https://ref.dm-lang.org/proc/prob.md)
- [rand proc](https://ref.dm-lang.org/proc/rand.md)
- [rand_seed proc](https://ref.dm-lang.org/proc/rand_seed.md)
- [range proc](https://ref.dm-lang.org/proc/range.md)
- [ref proc](https://ref.dm-lang.org/proc/ref.md)
- [refcount proc](https://ref.dm-lang.org/proc/refcount.md)
- [regex proc](https://ref.dm-lang.org/proc/regex.md)
- [REGEX_QUOTE proc](https://ref.dm-lang.org/proc/REGEX_QUOTE.md)
- [replacetext proc](https://ref.dm-lang.org/proc/replacetext.md)
- [replacetextEx proc](https://ref.dm-lang.org/proc/replacetextEx.md)
- [return statement](https://ref.dm-lang.org/proc/return.md)
- [rgb proc](https://ref.dm-lang.org/proc/rgb.md)
- [rgb2num proc](https://ref.dm-lang.org/proc/rgb2num.md)
- [roll proc](https://ref.dm-lang.org/proc/roll.md)
- [round proc](https://ref.dm-lang.org/proc/round.md)
- [run proc](https://ref.dm-lang.org/proc/run.md)
- [settings (proc)](https://ref.dm-lang.org/proc/set/index.md)
- [sha1 proc](https://ref.dm-lang.org/proc/sha1.md)
- [shell proc](https://ref.dm-lang.org/proc/shell.md)
- [shutdown proc](https://ref.dm-lang.org/proc/shutdown.md)
- [sign proc](https://ref.dm-lang.org/proc/sign.md)
- [sin proc](https://ref.dm-lang.org/proc/sin.md)
- [sleep proc](https://ref.dm-lang.org/proc/sleep.md)
- [sorttext proc](https://ref.dm-lang.org/proc/sorttext.md)
- [sorttextEx proc](https://ref.dm-lang.org/proc/sorttextEx.md)
- [sound proc](https://ref.dm-lang.org/proc/sound.md)
- [spantext proc](https://ref.dm-lang.org/proc/spantext.md)
- [spawn proc](https://ref.dm-lang.org/proc/spawn.md)
- [splicetext proc](https://ref.dm-lang.org/proc/splicetext.md)
- [splittext proc](https://ref.dm-lang.org/proc/splittext.md)
- [sqrt proc](https://ref.dm-lang.org/proc/sqrt.md)
- [startup proc](https://ref.dm-lang.org/proc/startup.md)
- [stat proc](https://ref.dm-lang.org/proc/stat.md)
- [statpanel proc](https://ref.dm-lang.org/proc/statpanel.md)
- [step proc](https://ref.dm-lang.org/proc/step.md)
- [step_away proc](https://ref.dm-lang.org/proc/step_away.md)
- [step_rand proc](https://ref.dm-lang.org/proc/step_rand.md)
- [step_to proc](https://ref.dm-lang.org/proc/step_to.md)
- [step_towards proc](https://ref.dm-lang.org/proc/step_towards.md)
- [switch proc](https://ref.dm-lang.org/proc/switch.md)
- [tan proc](https://ref.dm-lang.org/proc/tan.md)
- [text proc](https://ref.dm-lang.org/proc/text.md)
- [text2ascii proc](https://ref.dm-lang.org/proc/text2ascii.md)
- [text2file proc](https://ref.dm-lang.org/proc/text2file.md)
- [text2num proc](https://ref.dm-lang.org/proc/text2num.md)
- [text2path proc](https://ref.dm-lang.org/proc/text2path.md)
- [throw statement](https://ref.dm-lang.org/proc/throw.md)
- [time2text proc](https://ref.dm-lang.org/proc/time2text.md)
- [trimtext proc](https://ref.dm-lang.org/proc/trimtext.md)
- [trunc proc](https://ref.dm-lang.org/proc/trunc.md)
- [try and catch statements](https://ref.dm-lang.org/proc/try.md)
- [turn proc](https://ref.dm-lang.org/proc/turn/index.md)
- [typesof proc](https://ref.dm-lang.org/proc/typesof.md)
- [uppertext proc](https://ref.dm-lang.org/proc/uppertext.md)
- [url_decode proc](https://ref.dm-lang.org/proc/url_decode.md)
- [url_encode proc](https://ref.dm-lang.org/proc/url_encode.md)
- [values_cut_over proc](https://ref.dm-lang.org/proc/values_cut_over.md)
- [values_cut_under proc](https://ref.dm-lang.org/proc/values_cut_under.md)
- [values_dot proc](https://ref.dm-lang.org/proc/values_dot.md)
- [values_product proc](https://ref.dm-lang.org/proc/values_product.md)
- [values_sum proc](https://ref.dm-lang.org/proc/values_sum.md)
- [vars (procs)](https://ref.dm-lang.org/proc/var/index.md)
- [vector proc](https://ref.dm-lang.org/proc/vector.md)
- [view proc](https://ref.dm-lang.org/proc/view.md)
- [viewers](https://ref.dm-lang.org/proc/viewers.md)
- [walk proc](https://ref.dm-lang.org/proc/walk.md)
- [walk_away proc](https://ref.dm-lang.org/proc/walk_away.md)
- [walk_rand proc](https://ref.dm-lang.org/proc/walk_rand.md)
- [walk_to proc](https://ref.dm-lang.org/proc/walk_to.md)
- [walk_towards proc](https://ref.dm-lang.org/proc/walk_towards.md)
- [while proc](https://ref.dm-lang.org/proc/while.md)
- [winclone proc](https://ref.dm-lang.org/proc/winclone.md)
- [winexists proc](https://ref.dm-lang.org/proc/winexists.md)
- [winget proc](https://ref.dm-lang.org/proc/winget.md)
- [winset proc](https://ref.dm-lang.org/proc/winset.md)
- [winshow proc](https://ref.dm-lang.org/proc/winshow.md)
