| 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 Open BranchHere you will see how to use the relational oeprators prsented in the previous section. This is the beginning of having the ability to code decision-making capabilities into the NWN2 environment.
Basic Idea The basic idea behind the Open Branch is that there is a main part of the program that will always happen and a part of the program that may or may not happen depending on a condition. As an example, suppose you had an age check on one of the games creatures entering your castle. If the creature was over a certain age, you gave them a special greeting and gold. If, however the creature was not over that age, they got a standard greeting and no gold. One way of doing this woudl be by using the Open Branch which uses the if statment.
The if Statement The if statement is referred to as a conditionial statement because its execution will depend on a specific condition. The general form of the if statement is:
if (expression) statement
The program below illustrates an application of the open branch using the if statement:
The above program compiles without errors. Here are some facts about the program:
Where do we go from here? The next section introduces another important decision-making tool, the Closed Branch.
|
|