Location(object, vector, float)

From NWN Lexicon
Jump to navigationJump to search

Set the value of a Location data structure.

location Location(
    object oArea,
    vector vPosition,
    float fOrientation


An Area within the game module
An object specifying an xyz coordinate
An angular value between 0.0 and 360.0


This function is a location constructor. A constructor is a special type of function whose purpose is to create a new instance of its type. A constructor is also where any special construction actions or initialization takes place. Its return type is a new object of the specified type, so in this case what we get back is a new object of type location.

In order to construct a new location object the script needs three things:

  1. The area the location is referenced in (this is the Area of the Module).
  2. A new vector containing the x, y and z coordinates of this location.
  3. A float representing the facing of the object from 0.0 to 360.0 where 0.0 = East, 90.0 = North, 180.0 = West, and 270.0 = South.


Object creation is often one of the most expensive operations, in terms of CPU usage, that can be performed. The rule of thumb is "€œCreate as many objects as you need, but no more€".




// Locate the area we are in
object oArea = GetArea(OBJECT_SELF);

// Locate where in the are we are
vector vPosition = GetPosition(OBJECT_SELF);

// Identify the direction we are facing
float fOrientation = GetFacing(OBJECT_SELF);

// Create a new location with this information
location myLocation = Location(oArea, vPosition, fOrientation);

See Also

functions:  Vector

 author: Ryan Hunt, editor: Lilac Soul, additional contributor(s): George Kuff, Lilac Soul