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 Local Variables

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


NWN2 Local Varibles

  • NWN2 Local Variables are variables that can be accessed by any object.
  • NWN2 Local Variables come in three types: integer, float, and string.
  • NWN2 Local Variables can be used to store infomraiotn with a specific object.
  • NWN2 Local Variables can be used to get information from a specific object.
  • NWN2 Local Variables are prefered over NWN2 global variables because they are assigned to specific objects and in that sense protected.
  • NWN2 Local Variables add a powerful programming feature to the NWN2 scripting environment.

 


 

NWN2 Local Variables General Form

To decalre and assign a value to a NWN2 Local Variable:

SetLocalType(Object, "Identifier", Value);

Where:

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

NWN2 Local Variable Examples:

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


void main()

 {

  object oSelf=GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC

     SetLocalInt(oSelf, "Value1", 1);

     SetLocalFloat(oSelf, "Value2", 3.40);

     SetLocalString(oSelf, "Quest1", "Quest completed!");

 }

 


 

Explanation:

      For the SetLocalInt()

Term Meaning
SetLocalInt Keyword for setting a NWN2 Local Variable of data type Integer (int).
oSelf Identified object. In this case hte local variable is associated with the PC.
"Value1" The variable identifier. Note that it is of data type string and must be enclosed in quotes.
1 The value assigned to the variable identifier. Note that since this sets a Local int, this must be an integer.

      For the SetLocalFLoat()

Term Meaning
SetLocalFloat Keyword for setting a NWN2 Local Variable of data type Float (float).
oSelf Identified object. In this case the local variable is associated with the PC
"Value2" THe variable identifier. Note that it is of data type string and must be enclosed in quotes.
3.40 The value assigned to the variable identiifer. Note that since this sets a Local float, this must be a floating pionts number.

      For the SetLocalString()

Term Meaning
SetLocalString Keyword for setting a NWN2 Local Variable of data type String (string.)
oSelf
Identified object. In this case hte local variable is associated with the PC.
"Quest1"
The variable identiifer. Note that it is of data type string and must be enclosed in quotes.
"Quest Completed" The value assigned to the variable identifier. Note that since this sets a Local string, this must be enclosed in quotes.

 


 

Where do we go from here?

The next section introduces getting values from previously declared NWN2 Local 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.