Need loop help

I’m sure a simple loop would suffice for this. I just wish to find every placeable in the area the PC is in, which all have the same tag, and destroy them. Lilac Soul doesn’t do this and right now nothing is being destroyed. I think it is getting confused since there are a dozen objects with the same tag.

    object oPC = GetFirstPC();
    object oArea = GetArea(oPC);

    object oTarget = GetFirstObjectInArea(oArea);
    while (oTarget != OBJECT_INVALID)
        if (GetTag(oTarget) == "CAKETOWN")

        oTarget = GetNextObjectInArea(oArea);

Using GetFirstPC() to determine target PC here. May want to use something else, in case of multiple PCs.

Should be only one PC (planning on single player mod). However it is only destroying 2 of 12. Maybe I want to assign GetObjectByTag or GetNearestObjectByTag to oTarget? I may try that.


    int i = 1;
    object oTarget = GetNearestObjectByTag("CAKETOWN", oPC, i);
    while (oTarget != OBJECT_INVALID)

        oTarget = GetNearestObjectByTag("CAKETOWN", oPC, i);

Is there any reason why the tag might not be a match on the other ten?

Okay I get it, the others were checked “static”. Now it works. The other one probably would have worked too. So what does static actually do (besides make things invincible apparently)?

As I understand it, they’re exempt from various engine tasks, allowing placeables that are not meant to be usable to pose less of a performance drain. There seems to be something about the load order, too; for instance, placeables must be set to static to be able to alter the area walkmesh height (with a .wok attached). Wish I knew the details, too, though.

We’ve seen some pretty weird stuff happen with rendered surfaces, too. Some types of transparency and gloss don’t seem to want to work if the placeable isn’t static.

I just figured out something else static does, it makes them exempt from area effects. I just tested the area with a high level PC and used chain lightning to kill the rats. It obliterated half the debris I was trying to destroy. The object of destroying the debris is to make it look like a cleanup effort happened. I’d like to use a cut scene fade out/ fade in, but it is getting stuck on the fade out and not coming back. More work needed.

    FadeToBlack(oPC, FADE_SPEED_SLOW);
    DelayCommand(3.0, FadeFromBlack(oPC, FADE_SPEED_SLOW));


Static placeables are regarded by the engine as a permanent feature of the area, similar to tiles.

It’s beneficial to flag permanent placeables as static, because the engine renders them more efficiently and doesn’t waste time on them after that. Also, dynamic objects are not rendered beyond about 40m, so if you want something to always be visible, make it static.

However, a placeable should not be flagged as static if you ever want to change it, for example, by deleting it, animating it, turning its light on, or other scripting.

Some nwscript commands ignore static objects, as you just discovered. However, others don’t, so beware. It’s possible to introduce a very nasty bug if you succeed in deleting a static object by script. Nothing will tell you that something bad has happened, but the game can be corrupted from that point on.

1 Like

Thanks. In this particular case, unchecking static for my dozen items to later delete, but checking plot would ensure the expected results I want are achieved. Not likely a first level mage will have anything to destroy placeables, but just in case.

There’s something about the destroy object loop that is not allowing the fade from black to occur. Screen just stays black.

It’s probably the delayed command, if the caller of the script is one of the objects that are getting destroyed. Can’t do things if it doesn’t exist anymore.

Try setting up a custom void for the delayed fade, and assign it to the player in your script:

void DelayedFade(object oCaller=OBJECT_SELF, float fDelay=3.0, float fSpeed=FADE_SPEED_SLOW)
    DelayCommand(fDelay, FadeFromBlack(oCaller, fSpeed));

^- Add before void main.

Inside void main:

AssignCommand(oPC, DelayedFade());

Fingers crossed.

PERFECT! You are the code master!


No pedestals, please. x_x The higher they are, the harder the fall.

But, anytime. :slight_smile: Shout when the next issue pops up.