| 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 ? OperatorThere 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:
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.
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.
|
|