Skip to content

int nNth=1 ?

What does this mean in neverwinter script? I 've been trying to figure out how to plug this into a logical statement but do not understand the meaning of it.
Would someone type me an example of how you to complete a statement using the nNth component?
Thanks guys...

Comments

  • meaglynmeaglyn Member Posts: 151
    What you have posted is just saying a variable of type int named nNth gets the value of one. If it's in the declaration of a function the it means that an argument of type int is in that position when called and that it's optional and if left off will have a value of one in the called function. But your question does not really have enough information in it. Can you give an example of what you are trying to do?

    I'm guessing it's one of the GetNearestObject() type calls. There a lot's of examples of using those in the lexicon.
  • MelkiorMelkior Member Posts: 216
    int nNth=1;
    
    This statement combines two operations into a single statement. Firstly, it declares an integer variable named "nNth" and secondly it assigns the value of 1 to that variable. It is the equivalent of (but shorter and faster than) the following two statements:
    int nNth;
    nNth=1;
    
  • ZephiriusZephirius Member Posts: 419
    edited April 2023
    This is an example from the toolset. I don't understand what the parameter nNth requires to complete the statement.
    object GetNearestCreature(int nFirstCriteriaType, int nFirstCriteriaValue, object oTarget=OBJECT_SELF, int nNth=1, int nSecondCriteriaType=-1, int nSecondCriteriaValue=-1, int nThirdCriteriaType=-1,  int nThirdCriteriaValue=-1 )
    

    example:
    void main( )
    {
    	object oPC = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC);
    }
    

    In the toolset example, nNth is the fourth parameter in the function. What am I suppose to do with it?
  • ProlericProleric Member Posts: 1,316
    edited April 2023
    Have a look at GetNearestObject for a simpler case that explains the principle.

    Often, you just want the nearest object, so you can omit the final parameter (it defaults to one). Sometimes, though, you want to loop through all the objects, nearest first.
    int i = 0;
    object oTest = GetNearestObject(OBJECT_TYPE_CREATURE, GetFirstPC(), ++i);
    while (GetIsObjectValid(oTest))
      {
        // Do stuff to object
        oTest = GetNearestObject(OBJECT_TYPE_CREATURE, GetFirstPC(), ++i);
      }
    
  • meaglynmeaglyn Member Posts: 151
    Well, as I said, in that case it's an optional parameter which will be 1 if you don't pass anything in in that position. Which means the call will return the first (1th :) nearest creature. It is not required to "complete" the statement.

    But you don't have to do anything with it in your example.

    You could use it in a loop to find, say the 4 nearest creatures, for example. Or you could set it to say 3 to get the third nearest creature.
  • TarotRedhandTarotRedhand Member Posts: 1,481
Sign In or Register to comment.