Skip to content

Help setting up a loop

I'm building a puzzle in which I need to target all instances of a placeable with the same tag ("LightMechanism"). There are about eight of them in my area, and I want the system to keep on working in case I add more of them. So I'm trying to cycle between them with a loop but it's not working. It's even crashing the game because the loop keeps on going endlessly. Can someone help?

FYI, I've created the ChangeShaftColor function and it's working properly.
    int nMech = 1;
    object oMechanism = GetNearestObjectByTag("LightMechanism", OBJECT_SELF, nMech);

    while (GetIsObjectValid(oMechanism) == TRUE)
    {
        object oShaft = GetNearestObjectByTag("GlassAltarShaft", oMechanism);

        ChangeShaftColor(oShaft, sColor);

        int nMech = nMech + 1;
        oMechanism = GetNearestObjectByTag("LightMechanism", OBJECT_SELF, nMech);
    }

Comments

  • DazDaz Member Posts: 125
    int nMech = nMech + 1;
    
    You're resetting the variable here. Change it to following and it should work:
    nMech = nMech + 1;
    
  • gpeddinogpeddino Member Posts: 50
    You were right, it worked! Thanks a lot!
Sign In or Register to comment.