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

Setting Global Variables

NWN2 has a special way of handling global variables. These are global variables in standard C++, however their use is somewhat different from how they are used in NWN2.


NWN2 Global Variables

  • NWN2 Global Variables are variables that can be accessed any where in a module.
  • NWN2 Global Variables come in three types: integer, float, and string.
  • NWN2 Global Variables can be used to store information from anywhere in a module.
  • NWN2 Global Variables can be used to get information from anywhere in a module.
  • NWN2 Global Variables should be used sparingly, especailly in large moduls with more than one developer since a developer may set its value in one part of the module and unknowingly corrupt other sections of the module.
  • NWN2 Global Variables add a powerful programming feature to the NWN2 scripting environement.

 


NWN2 Global Variables General Form

To declare and assign a value to a NWN2 Global Variable:

SetGlobalType("Identifier", Value);

Where:

  • Type is one of three allowed data types of: Int, Float, or String.
  • Identifier is the token used to identify the variable, this may be any string.
  • Value is the actual value assigned to the NWN2 Global Variable consistent with the data type.

 


 

NWN2 Global Variable Examples:

The following program illustrates examples of declaring and assigning values to the three allowed data types for a NWN2 Global Variable.

void main()

 {

   SetGlobalInt("Value1, 1);

    SetGlobalFloat("Value2", 12.075);

    SetGlobalString("Value2", "Welcome to NWN2!");

  }

Explanation:

         For the SetGlobalInt()

Term Meaning
SetGlobalInt Keyword for setting a NWN2 Global Variable of data type Integer (int).
"Value1" The variable identifier. Note that it is of data type string and must be enclosed in quotes.
1 The value assigned to hte variable identifier. Note that since this sets a global int, this must be an integer.

      For the SetGlobalFLoat()

Term Meaning
SetGlobalFloat Keyword for setting a NWN2 Global Variable of data type Float (float).
"Value2" The variable identifier. Note that it is of data type string and must be enclosed in quotes.
12.076 The value assigned to the variable identifier. Note that since this sets a global float, this must be a floating point number.

      For the SetGlobalString()

Term Meaning
SetGlobalString Keyword for setting a NWN2 Global Variable of data type String (string.)
"Value3" The variable identiifer. Note that it is of data type string and must be enclosed in quotes.
"Welcome to NWN2!" The value assigned to the variable identiifer. Note that since this sets a global string, this must be enclosed in quotes.

 


 

Where do we go from here?

The next section introduces getting values from previously declared NWN2 Global Variables.

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.