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

The ? Operator

There is another way of expressing a simple if-else statment. This can be done by using the syntax of the ? operator. This section explains what that operator is and an example of how to use it.


if else Example

An if-else example is illustrated in the following program:

void main()

{

int Age;

string Message;

object oPC=GetEnteringObject();

 Age=GetAge(oPC);

if(Age>100)

 Message="welcome wise one.";

else

 Message= "Hello Dude";

FloatingTextStringOnCreature(Message, oPC);

}

 


 

The above program checks the PCs age and if the age is greater than 100 is greeted with Welcome wise one. Otherwise (else) the PC is greeted with  Hello Dude. Note that forsingle statements following and if or an else, no braces { } are necessary. Their omission in the above program is not an error.

 


 

Example ? Operator

The program below illustrates the use of the ? operator. This program does exactly the same thing that the previous program did. It just uses a different syntax to do it.

void main()

{

int Age;

string Message;

object oPC=GetEnteringObject();

 Age=GetAge(oPC);

(Age>100)?(Message="Welcome wise one."):(Message="Hello Dude!");

 FloatingTextStringOnCreature(Message, oPC);

}

The syntax for the ? Operator is:

(statement)?(option1):(option2);

If statement is TRUE, then option1 will be executed.

If statement is FALSE, then option2 will be executed.

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.