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.
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.