Goonstation 13 - Modules - TypesDefine Details

_std/types.dm

ENSURE_TYPEnulls a var if its value doesn't match the var's type
/proc/concrete_typesof[/proc/typesof()] but only for concrete (not abstract) types, it caches the result so you don't need to worry about doing that manually so subsequent calls on the same type will be very fast.
/proc/filtered_concrete_typesofThe same thing but now you can filter the types using a proc. Also cached. The filter proc takes a type and should return 1 if we want to include it and 0 otherwise. That proc should also be pure (always return the same thing for the same arguments) because of the caching. If you want to use non-pure proc do the filtering manually yourself and don't use this. Note that the first call to filtered_concrete_typesof with a given type and filter will be (possibly a lot) slower than doing it manually. The benefit of this proc only shows itself for future calls which are very fast due to caching.
/proc/get_singletonGets the instance of a singleton type (or a non-singleton type if you decide to use it on one).
/proc/predecessor_path_in_listFind predecessor of a type
/proc/maximal_subtypeReturns the maximal subtype (i.e. the most subby) in a list of given types
/var/by_typecontains lists of objects indexed by their type based on [START_TRACKING] / [STOP_TRACKING]
for_by_tclLoops over all instances of a type that's tracked via the [START_TRACKING] and [STOP_TRACKING] macros. Example: for_by_tcl(gnome, /obj/item/gnomechompski) qdel(gnome)
/var/by_catcontains lists of objects indexed by a category string based on START_TRACKING_CAT / STOP_TRACKING_CAT
/typeinfotype-level information type
TYPEINFODeclares typeinfo for some type.
/proc/get_type_typeinfoRetrieves the typeinfo datum for a given type.
/proc/type2parentReturns the parent type of a given type. Assumes that parent_type was not overriden.
/proc/find_first_by_typeFinds some instance of a type in the world. Returns null if none found.
/proc/find_all_by_typeFinds all instance of a type in the world. Returns a list of the instances if no procedure is given. Otherwise, calls the procedure for each instance and returns an assoc list of the form list(instance = procedure(instance, arguments...), ...) procedure_src is the src for the proc call. If it is null, a global proc is called. If it is the string "instance" the output list will be instead list(instance = instance.procedure(arguments...), ...)
/proc/istypesistype but for checking a list of types
/proc/get_random_subtypeReturns a random subtype when an atom has TYPEINFO with a random_subtypes list
/proc/string_type_of_anythingthing.type but it also returns "num" for numbers etc.

Define Details

ENSURE_TYPE

nulls a var if its value doesn't match the var's type

TYPEINFO

Declares typeinfo for some type.

Example:

TYPEINFO(/atom)
	var/monkeys_hate = FALSE

TYPEINFO(/obj/item/clothing/glasses/blindfold)
	monkeys_hate = TRUE

Treat this as if you were defining a type. You can add vars and procs, override vars and procs etc. There might be minor issues if you define TYPEINFO of one type multiple times. Consider using /typeinfo/THE_TYPE for subsequent additions to the object's typeinfo if you know it has already been declared once using TYPEINFO.

for_by_tcl

Loops over all instances of a type that's tracked via the [START_TRACKING] and [STOP_TRACKING] macros. Example: for_by_tcl(gnome, /obj/item/gnomechompski) qdel(gnome)