typegraph/scripts/generic/instanceof.gml

24 lines
529 B
Plaintext

///instanceof(id, ind)
/**
* instanceof :: Instance -> Class -> Boolean
*
* Returns whether `id` is of type `ind`, either directly or via the parent hierarchy.
*
* @param id the instance to check
* @param ind the object type to check for
* @returns true if id is of type ind, false otherwise
*/
var inst = argument0;
var ind = argument1;
if (!instance_exists(inst))
return false;
for (var obj = inst.object_index; object_exists(obj); obj = object_get_parent(obj))
if (obj == ind)
return true;
return false;