Count all game objects in module with tag

So, title is self explanatory. I know there is a way to do it for an area, but is there a way to do it for the entire module? Or do I now have to create a script that scrolls through all the areas in my module and counts them per area… ?

GetObjectByTag has an integer parameter that lets you target the nth object with that tag. You can cycle through them like this, incrementing a counter by 1 each round of the while loop.

    int i;
    object oTarget = GetObjectByTag("INSERT_TAG_HERE");
    while (oTarget != OBJECT_INVALID)
        // Do things with oTarget.

        oTarget = GetObjectByTag("INSERT_TAG_HERE", ++i);

Oh, wait…you mean to tell me that GetObjectByTag works across the entire module?:flushed::flushed::flushed:

1 Like

:grin: Yep. Those damned sneak attack “oh snap, it was that easy the entire time???” revelations, amiright? Like getting a hammer to the face. A while back, pscythe looked at a code snippet of mine and went “How come you’re not using a ‘break’ here?” and I didn’t even know what a break was. Fuck! Love the lesson learned, became better scripter because of it, but still. Gah!! The feels.

I think we shouldn’t kick ourselves for stuff like that, though. :slight_smile: The more free people feel to ask questions and get answers, the faster we all learn. There’s always a lurking newbie or two around who still need a bit of encouragement to get bold enough to start asking questions at all, too, so every opportunity to publicly demonstrate that nobody’s getting their heads bitten off for saying or asking the wrong thing is worthwhile in itself.

::boogies the boogie of ‘On to the next “embarrassing” situation! Bring it on, life!’::

1 Like
object GetNearestObjectByTag(
    string sTag,
    object oTarget = OBJECT_SELF,
    int nNth = 1

^ Works only for objects which are in the same area as the target object.

object GetObjectByTag(
    string sTag,
    int nNth = 0

^ Works for object in the entire module.

1 Like