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

Getting Local Variables

In the previous sessoin you saw how to assign values to NWN2 Local Variables. In this session you will see how to get the values from previously declared and defined NWN2 Local Variables.


NWN2 Local Variables General Form

To get a value from a previously declared and assigned NWN2 Local Variable:

GetLocakType(Object, "Identifier");

Where:

  • Type is one of three allowed data types of: Int, Float, or String.
  • Object is any legal NWN2 object.
  • Identifier is the token used to identify the variable, this may be any string that has previously been assigned to the given Obejct


NWN2 local Variable Examples:

The following program illustrates examples of getting values from previously declared and assigned NWN2 Local Variables assigned to the PC, with the three different NWN2 Local Variable data types.

void main()

 {

 object  oSelf=GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PAYER_CHAR_IS_PC);

  int intValue;

  float fltValue;

  string stgValue;

  intValue=GetLocalInt(oSelf, "MyInt");

  fltValue=GetLocalFLoat(oSelf, "MyFloat");

  stgValue=GetLocalString(oSelf, "MyString");

 }

 


Explanation:

       For the GetLocalInt()

Term Meaning
GetLocalInt Keyword for getting a value from a NWN2 Local Variable of data type Integer (int).
oSelf Identified object. In this case the local variable is associated with the PC.
"MyFLoat" The variable identifier. Note that it is of data type string and must be enclosed in quotes.
intValue The variable that will receive the previously assigned value. Note that this must be a data type int.

      For the GetLocalFLoat()

Term Meaning
GetLocalFloat Keyword for getting a value from a NWN2 Local Variable of data type Float (float).
oSelf Identified object. In this case the local variable is associated with the PC
"MyFloat" The variable identifier. Note that it is of data type string and must be enclosed in quotes.
fltValue The variable that will receive the previously assigned value. Note that this must be of data type float

      For the GetLocalString()

Term Meaning
GetLocalString Keyword for getting a value from a NWN2 Local Variable of data type String (string.)
oSelf
Identified object. In this case hte local variable is associated with the PC.
"My String"
The variable identiifer. Note that it is of data type string and must be enclosed in quotes.
"stgValue" THe variable that iwll receive the previously assigned value. Note that thi smust be of data type string.

 


 

Where do we go from here?

This concludes the section on NWN2 Global and 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.