Understanding Secret Door Template

I want to start off by saying I’m new to Neverwinter the game and the tool set as well.
I also know a little bit about C++ and Im currently writing Scripts on a module with friends and wanted to better.

So I’m going to paste a function that I do not quite understand to the fullest but would like to go into more, This is also from the Secret Door template from the expansion pack 2 Underdark.

int nBestSkill = -50;
object oidBestSearcher = OBJECT_INVALID;
int nCount = 1;

// Find the best searcher within the search radius.
object oidNearestCreature = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC);
int nDoneSearch = 0;
int nFoundPCs = 0;

while ((nDone == 0) &&
       (nDoneSearch == 0) &&
       (oidNearestCreature != OBJECT_INVALID)
    if(GetMaster(oidNearestCreature) != OBJECT_INVALID || GetIsPC(oidNearestCreature))
        // what is the distance of the PC to the door location
        float fDist = GetDistanceBetween(OBJECT_SELF,oidNearestCreature);

        if (fDist <= fSearchDist)
            if (LineOfSightObject(OBJECT_SELF, oidNearestCreature) == TRUE)
                int nSkill = GetSkillRank(SKILL_SEARCH,oidNearestCreature);

                if (nSkill > nBestSkill)
                    nBestSkill = nSkill;
                    oidBestSearcher = oidNearestCreature;
                nFoundPCs = nFoundPCs +1;
                //The Secret door is on the other side of the wall - so don't find it
                nDoneSearch = 1;
            // If there is no one in the search radius, don't continue to search
            // for the best skill.
            nDoneSearch = 1;
    nCount = nCount +1;
    oidNearestCreature = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC, OBJECT_SELF ,nCount);

This is the text I think is relevant in better understanding the while loop which is the function. I guess my question would be for the parameters next to the while function, what would make the statement false, And in turn breaking the loop. I have a hard time understanding that part of the function in this script. I also think I get confused on the two && symbols In the parameters.

Thank you for the help in advance.

Hi. :smiley:

Read this, it’ll explain everything:

While loop translated:
While nDone is zero, and nDoneSearch is zero, and oidNearestCreature is not OBJECT_INVALID, do (thing).

nDoneSearch is being set to 1 in some cases, and oidNearestCreature can change, cycling through all the nearby players until it returns OBJECT_INVALID. Either of these would break the while loop.

Links to the other parts of Tarot’s Basics series:

Also, to the Lexicon:

1 Like

Thank you for the reply and much appreciated for the references, I was under the impression that the “&&” symbol meant both conditions had to be met in order for the statement to stay true thus keeping the loop until false. In this case three conditions, nDone is zero, and nDoneSearch is zero, and oidNearestCreature is not OBJECT_INVALID.

But what you’re saying is that either statement which is “donesearch” is zero or “oidnearestcreature is not object_invalid” can be false in order to break the loop?

In any conditional that features the && (and) statement it only takes one to be false to make the whole statement return false.


1 Like

What condition symbol would have to make both statements true in order to break the loop?

Simply put you would enclose an && in parenthesis and place the ! (not) operator in front of it like -

!(x == x && y == y)

This is equivalent to having an operator called a nand (stands for Not And). The easiest way (well I think so) is to read through the tutorial I wrote on Boolean Algebra as all of these are covered in it. It is here.




Fair enough will definitely look through the PDF but couldn’t you just achieve the same results by leaving the not symbol out? (!) EX. (x == x && y == y)

Or does that not work when compiling, And thanks again for your feedback :slight_smile:

You asked for a way to return false when you feed in true. That is the job of the not operator. It “inverts” what ever you give it. so false becomes true and true becomes false. Without those brackets it would only apply the “not action” to the first variable.


Oh I see my bad I was inadvertently asking the opposite but it still makes sense Thank You :slight_smile:

Just so that it doesn’t look like a total promotion for my series here’s a couple more links you might find useful -





ku ku Thank You