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

First Program

Your first program is the simplest program possible. To check if the program is correct in the NWN2 editor you only need to click on the Compile button or use the key F7. If there are no errors in the program you will see a messag ein the compile results box that the compilation was successful. If the program is nto correct, you will see an error message there.


Your First Program

Below is your first program:

void main()

 {

 

 }


The above program compiles without errors. Here are some facts about this program:

  • Everythign is in lower case letters.
  • The very first word is void.
  • The next word is main.
  • Immediatlyl after the word main are a set of parentheses: ()
  • The body of the program starts with an opening brace: {.
  • The end of the body of the program ends with a closing brace: }.

Another way of writing the same program.

The above program could have also been written as shown below:


void main() { }

 


 

The above progarm would sitll compile without errors. The placement of the openign and closing braces { } is simply a programmers choice. We will use the way shoawn in the first progrm above.

 


 

What Each Part Means

The table below lists the purpose of each part of our most basic program:


Item Purpose
void This is the return type for the main program function. We will see
later that C++ programs are broken up into functions that do
somethign and generally return a value. Every C++ program
must contain a main function and the void simply tells the
compiler that this function will not return any value.
main This is the requried function in all C++ programs. It stats with the
keyword main. A keyword is simplay a word that has a special
meaning in C++ main is the keyword that identifies the main
function.
( ) These parentheses must immediatly follow the main keyword. You
will see later that we can put important values between these
parentheses for the function to work on. When they are empty, as
shown here, these are no values passed to this function.
{ The opening brace { tells the C++ compiler where the function starts.
You can think o htis as a begin statment.
} The closing brace } tells the C++ compiler where the funciton ends.
You can think of this as an end statment.
 


What does the Above Program Do?

Nothing! It simply serves as an example of the simpliest possible C++ program that will successfully compile.


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.