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

Compound Assignments

Compound assignments combine the simple arithmetic operators (sometimes called assignment operators) with another operator. Doing this allows for keeping program code brief.


Programming Example

The following example shows the basic compount assignment operators in action.


void main( )
  {
    int V  = 2;
     V +=2; // V=V + 2 = 4
     V -=1; // V - 1=1
     V *=3; //V X 3 = 6
     V /= 2; //  V/2 = 1
     V %= 2; // V mod 2 = 0;
  }



An analysis of the above program yields:
•    One variable V was declared and given an assignment of 2.
•    The compound assignment operators were preformed using the value of the assigned variable.
•    Each compound assignment operation is commented to show the numeric meanings of the given compound assignment operation.


Standard Compound Assignment Operators

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

Symbol Example Meaning
+= X += Y X=X+Y
-= X -= Y X=X-Y
*= X *= Y X=X*Y
/= X /= Y X=X/Y
%= X %= Y X=X%Y


These compound assignment 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.