Iterating over classes during preinit in T3/adv3?

Is there any way to iterate over class definitions during preinit? Specifically I want to iterate over all Action classes that are subclasses of a specific class. E.g. something like:

        execute() {
                forEachInstance(FoozleAction, function(o) {
                        // do stuff

…except that iterates over instances, and actions aren’t instanced like that.

1 Like

I think you want to use the ObjClasses flag (which can’t be passed to forEachInstance() due to how it’s implemented):

for (local obj = firstObj(TAction, ObjClasses); obj != nil; obj = nextObj(obj, TAction, ObjClasses))

I think you can do that with the firstObj() and nextObj() functions. Pass the ObjClasses flag to only iterate over class objects (note that classes are also objects, which is why this works.)


An example of how to iterate over all SystemAction subclasses (excluding the SystemAction class itself):

local classObj = firstObj(SystemAction, ObjClasses);
while (classObj != nil) {
    // Do stuff. We just print the object name here.

    classObj = nextObj(classObj, SystemAction, ObjClasses);

Jim was way faster as I was typing and testing this :stuck_out_tongue:


Ah, cool. I’d also tried firstObj()/nextObj(), only without ObjClasses and that obviously didn’t work.

1 Like