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

Arithmetic Operators

The NWN2 scripting editor offers the standard C++ arithmetic operators. These operators offer the programmer and gamer powerful opportunities to do all kinds of interesting operations on manycharacteristics of the game. This section shows what the standard arithmetic operators are and how to use them.\


 

Programming Example

The following example shows the basic arithmetic operators in operation.


void main( )
 {
    int V1 = 2;
    int V2 = 4;
    int VTl;
    int VT2;
    int VT3;
    int VT4;
    int VT5;

     VT1=V1+V2;//2+4=6
     VT2=V1-V2;//2-4=-2
     VT3=V1 * V2;//2X4=8
     VT4 = V2/V 1; // 4/2 = 2
     VT5 = 4%2; // 4 mod 2 = 0
 }


An analysis of the above program yields:
•    Seven variables were declared and the first two given assignments.
•    The basic arithmetic operations were preformed using the values of the assigned
•    Each arithmetic operation is commented to show the numeric meanings of the given arithmetic operation.


Standard Arithmetic Operators

The table below lists the standard arithmetic operators and their meaning.

Symbol Meaning Example
+ Addition Ans = 3 + 4 (Ans = 7)
- Subtraction Ans = 5 - 3 (Ans = 2)
* Multiplication Ans = 5 * 3 (Ans = 15)
/ Division  Ans = 10/2 (Ans = 5)
% Remainder (Mod) Ans = 3%2 (Ans = 1)


These standard arithmetic operators are the ones used in standard C++ as well as in the C++ compiler that comes with the NWN2 editor.


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.