ID:1878985
 
(See the best response by Rotem12.)
Code:


Problem description:
If the parent type of all monsters has New() set to do something, all its children should do the same. I'm not sure how, but that's not happening. I didn't include any code, because this explains itself pretty much.

My problem with typesof is that it always includes the parent type in types of weather you were write it as /obj or as /obj/ shouldn't the / at the end tell it NOT to include the parent type?

Hork wrote:
Problem description:
If the parent type of all monsters has New() set to do something, all its children should do the same. I'm not sure how, but that's not happening. I didn't include any code, because this explains itself pretty much.
The top-level monster/New() might not be called if you have a letsay, monster/blob/New() that doesn't call the parent function via ..()


My problem with typesof is that it always includes the parent type in types of weather you were write it as /obj or as /obj/ shouldn't the / at the end tell it NOT to include the parent type?

No? I don't think that's documented behavior anywhere; you could just do typesof(/obj)-/obj.
Hork wrote:
My problem with typesof is that it always includes the parent type in types of weather you were write it as /obj or as /obj/ shouldn't the / at the end tell it NOT to include the parent type?

No, because type paths are internally handled as IDs rather than strings, each ID representing a specific prototype in the hierarchy. Therefore the compiler treats the / at the end as syntactic junk, since there's no way to differentiate between /obj and "any child of /obj".
Best response
You can do something like this to get rid of parent types
mob/verb/testTypes()
var/lastType
for(var/t in typesof(/mob))
if(ispath(lastType, t)) continue
world << "[t]"
lastType = t


typesof() appears to list children first and parent types afterwards so if the last type listed is a child of the current, it's a parent type.
Don't count on the list order of typesof() staying that way. If a list doesn't explicitly say it's in a specific order, the order is arbitrary and subject to change.
Can I count on the parent type to always be either first or last though?

It seemed pretty consistent when I tested it, one could hope.
The general rule is: You can't count on any list order that isn't documented. The implementation could change down the line. It probably won't, and if it's consistent now that means it'll probably always be so, but if I were to make a change in the future I wouldn't take into account any code that relies on this.

But that's kind of moot, as subtracting the original type from the list is enough to serve the OP's purposes.