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

Else If

You can compound else if statments. Doing this can offer you a range of selections that goes beyond the simple two selectiosn if the if else.


The Else If

The else if statment can be viewed as

              if (expression1) statment1 else if (expression2) statment2 else statment3

What this mean is that if expression1 is TRUE then statment1 will be executed and none of the other statments. If expression2 is TRUE, then statment2 will be excuted and none of the others. If neither expression1 nor expression2 are TRUE then statement3 will be executed and none of the others.

This series may be used as many times as you like with the general form of:


if...

else if...

else if...

.

.

.

else

An example of the use of the else if is shown in the following program:

 

//Checks the age range of a creature and

//charges acordingly.

void main()

  {

   object oPC=GetEnteringObject();

   string Message;

   int Gold;

   int Age;

   Age=GetAge(oPC);

   if(Age<20)

     {

       Message="Hell youngster, you get a youth discount.";

       Gold=3;

       TakeGoldFromCreature(Gold,oPC);

     }

   else if(Age>=20||(Age<100))

     {

       Message="The standard fee is 10 gold.";

       Gold=10;

       TakeGoldFromCreature(Gold, oPC);

     }

   else

      {

      Message="you must qualify for a senior discount!";

      Gold=5;

      TakeGoldFromCreature(Gold, oPC);

     }

FloatingTextStringOnCreature(Message, oPC);

}


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

  • The program makes three checks on the age range of a creature.
  • The first age range check is done by the first if statment to see if the creature is less than 20.
  • THe second age range check is done by the else if statment to see if the creatures age range is equal to or greater than 20 and less then 100.
  • The final else statment assumes that if none of the above criteria is true then the creature must be over 100.

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.