NWN2 Scripting.




Simulation Training.

Introduction
Home
First Program
Seeing Results
Variables and Data Types
Comments
Functions
Data Conversion
Random Numbers
Concatenation
Arithmetic Operators
Compound Assignments
One More or Less
Precedence
Relational Operators
The Open Branch
The Closed Branch
Logical AND
Logical OR
Compound Statements
ELSE If
Switch Case
The ? Operator
The for Loop
The while Loop
The do while Loop
Introduction to Functions
Passing Values
Passing Multiple Values
Multiple Functions
Simplifying Functions
TRUE/fALSE Conditions
Return Values
Setting Global Variables
Getting Global Variables
Setting Local Variables
Getting Local Variables
WayPoints Introduction
Static Waypoint Sets
Dynamic Waypoint Sets
Dynamic WP Cycles
Input Output

Logical AND

Another logical condition used by C++ is the And condition. This condition is a powerful addition to constructing gaming AI.


The Logical AND

The Logical AND operation is expressed as:

                                          (expression1) && (expression2)

The above expressiosn will be evaluated TRUE only if expression1 and expression2 are both TRUE, otherwise the oepration will be evaluated as FALSE.

In the NWN2 editor, TRUE is a 1 and FALSE is a 0. Observe that the double && is used to represent the AND operation:

expression1 expression2 Result
TRUE TRUE TRUE
TRUE FALSE FALSE
FALSE TRUE FALSE
FALSE FALSE FALSE

 


 

Logical && Example

An example of the logical && operation is illustrated in the following program.


//Checks the name of the PC and gives or takes gold.

void main()

{

 object oPC=GetEnteringObject();

 int Gold=200;

 string LastName;

 string FirstName;

 string Message;

 FirstName=GetFirstName(oPC);

 LastName=GetLastName(oPC);

if(FirstName==" Akon ") && (LastName==" Mordan"))

   {

    Message="Here is the gold you wanted.";

    GiveGoldToCreature(oPC, Gold);

   }

 else

   {

    Gold=50;

    Message="That will be 50 gold please.";

    TakeGOldFromCreature(Gold, oPC);

   }

FloatingTextStringonCreature(Message, oPC);

}

 

 


 

The above program compiles without errors. Here are some facts about the program:

  • The program checks the first and last name of a creature.
  • If the creatures first name is Akon AND its last name is Mordan then gold is given.
  • If the above conditions are not met, then gold is taken from the creature.
  • Note the use of the parenthesises ((expression1) && (expression2)). This is not done so the final test is evaluating just one TRUE or FALSE condition.

 


 

Where do we go from here?

The next section introduces more decision-making techniques with the introduction of logical OR.

Nwn2Scripting provides material for training only. We do not warrant the correctness of its contents. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.

Copyright 2008 by Adamson House, Ltd. All Rights Reserved.

Questions or Comments: EMail Webmaster

Donations are to Adamson House, Ltd who maintains this site.
All donations go the the improvement of this site.